//package com.opc.Service.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.opc.Common.MessageConstant;
//import com.opc.Config.CacheUtil;
//import com.opc.Mapper.*;
//import com.opc.Pojo.*;
//import com.opc.Service.AsyncMessage;
//import com.opc.Service.CarService;
//import com.opc.Service.JSerialCommIOService;
//import com.opc.Service.OpcUaService;
//import com.opc.properties.CarNodeProperties;
//import com.opc.properties.CarTypeProperties;
//import com.opc.properties.FrequencyProperties;
//import com.opc.properties.IpProperties;
//import com.opc.websocket.WebSocketServer;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.math.NumberUtils;
//import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
//import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
//import org.eclipse.milo.opcua.sdk.client.nodes.UaNode;
//import org.eclipse.milo.opcua.stack.core.AttributeId;
//import org.eclipse.milo.opcua.stack.core.Identifiers;
//import org.eclipse.milo.opcua.stack.core.UaException;
//import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
//import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
//import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
//import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
//import org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode;
//import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
//import org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateRequest;
//import org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters;
//import org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId;
//import org.quartz.*;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.util.CollectionUtils;
//import org.springframework.util.StringUtils;
//
//import java.io.IOException;
//import java.nio.file.Files;
//import java.nio.file.Path;
//import java.nio.file.Paths;
//import java.time.LocalDate;
//import java.time.format.DateTimeFormatter;
//import java.util.*;
//import java.util.concurrent.ExecutionException;
//import java.util.concurrent.atomic.AtomicInteger;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
//@Service
//@Slf4j
//public class OpcUaServiceImpl implements OpcUaService {
//
//    @Autowired
//    private CarNodeProperties carNodeProperties;
//    @Autowired
//    private CarNumPrefixMapper carNumPrefixMapper;
//    @Autowired
//    //@Qualifier("jSerialCommIOService")
//    private JSerialCommIOService jSerialCommIOService;
//    @Autowired
//    private WebSocketServer webSocketServer;
//    @Autowired
//    private CarService carService;
//    @Autowired
//    private CarMapper carMapper;
//    @Autowired
//    private IpProperties ipProperties;
//    @Autowired
//    private CarTypeProperties carTypeProperties;
//    @Autowired
//    private FrequencyProperties frequencyProperties;
//    @Autowired
//    private Scheduler scheduler;
//    @Autowired
//    private OpcUaService opcUaService;
//    @Autowired
//    private ScrewTypeMapper screwTypeMapper;
//    @Autowired
//    private CarStatusMapper carStatusMapper;
//    @Autowired
//    private AsyncMessage asyncMessage;
//    @Autowired
//    private TorqueStandardsMapper torqueStandardsMapper;
//
//    public static String formatToYYMMDD(String todayStr) {
//        if (todayStr == null || todayStr.length() != 10) {
//            log.info("yyyy-MM-dd格式不正确");
////            throw new IllegalArgumentException("Input string must be in yyyy-MM-dd format");
//        }
//        // 截取年份的后两位
//        String year = null;
//        if (todayStr != null) {
//            year = todayStr.substring(2, 4);
//        }
//        // 截取月份
//        String month = null;
//        if (todayStr != null) {
//            month = todayStr.substring(5, 7);
//        }
//        // 截取日期
//        String day = null;
//        if (todayStr != null) {
//            day = todayStr.substring(8, 10);
//        }
////        if (day.startsWith("0")) {
////            day = day.substring(1);
////        }
//        // 组合成 yyMMdd 格式
//        return year + month + day;
//    }
//
//
//    /**
//     *Administrator
//     * 创建OPC UA客户端
//     * @return
//     * @throws Exception
//     */
//    @Override
//    //@Suspendable
//    //如果createClient方法中包含可能阻塞的操作，
//    // 并且您希望这些操作在协程中执行，以避免阻塞整个线程，
//    // 那么加上@Suspendable注解是有意义的。
//    public OpcUaClient createClient() throws ExecutionException, InterruptedException {
//        OpcUaClient client = null;
////        log.info("创建客户端"+client);
//        Path securityTempDir = Paths.get(System.getProperty("java.io.tmpdir"), "security");
//        try {
//            Files.createDirectories(securityTempDir);
//        } catch (IOException e) {
//            log.info("创建文件异常");
//            log.info(e.getMessage());
//            e.printStackTrace();
////            throw new RuntimeException(e);
//        }
//        log.info("连接到的节点是"+ipProperties.getEndPointUrl());
//        if (!Files.exists(securityTempDir)) {
//            log.info("文件不存在");
//            try {
//                log.info("无法创建安全目录dir:");
//            } catch (Exception e) {
////                log.info("RuntimeException");
//                log.info(e.getMessage());
//                e.printStackTrace();
////                throw new RuntimeException(e);
//            }
//        }
//        int retryCount = 0;
//        int maxRetry = 8;
//        long waitTime = 1500; // 初始等待时间设置为1500毫秒
//        long MAX_WAIT_TIME = 6000;
//
//        while (true){ // 无限循环，直到连接成功
//            // 清理之前创建的所有节点
////            clearExistingNodes();
////            OpcUaClient client = null;
////            log.info("重建节点。。。");
////            //等待释放资源
////            try {
////                Thread.sleep(MAX_WAIT_TIME);
////            } catch (InterruptedException e) {
////                e.printStackTrace();
////            }
//            try {
//                //-----------------------------
//                Thread.sleep(3000);
//                //数据测试
//                Map map0 = new HashMap<>();
//                map0.put("car1Num", "254");
//                map0.put("car1Type", "485D");
//                map0.put("repeat1", "12");
//                map0.put("car2Num", "316");
//                map0.put("car2Type", "117D");
//                map0.put("repeat2", "14");
//                map0.put("standard1min", "18.5");
//                map0.put("standard1max", "30.8");
//                map0.put("standard2min", "16.5");
//                map0.put("standard2max", "21.0");
//                String json0 = JSON.toJSONString(map0);
//                webSocketServer.sendToAllClient(json0);
////--------------------------------------
//                Object alarmsTime0 =  CacheUtil.getFromCache("alarmsTime");
//                int alarmsTime = 0;
//                if(alarmsTime0!=null){
//                    alarmsTime = (int) alarmsTime0;
//                }
//
//
//                long ScrewId1 = 1;
//                int screwTypeId1;//5, 6, 8, 7, 2, 1, 3, 4, 13, 14, 15, 16, 9, 10, 11, 12
//                List<Integer> screwNum51List = Arrays.asList(5, 6, 7, 8, 1, 2, 3, 4);
//                for (int count = 0; count <= 7; count++) {
//                    Map map = new HashMap();
//                    //清理前端的所有信息缓存红点等等
////                                    map.put("alert", -1);
////                                      map.put("alert", 2);//全红
////                                    map.put("alert", 0);//全红
//                    map.put("alert", 1);//全绿
//                    Object object = CacheUtil.getFromCache("redLight");
////                                    List<Long> redLight0;
//                    if (object == null){
//                        List<Long> redLight0 = new ArrayList<>();
//                        redLight0.add(ScrewId1);
//                        log.info("没有红灯缓存，新建"+redLight0);
//                        CacheUtil.putInCache("redLight",redLight0);
//                    }else {//如果有就加多一个
//                        List<Long> redLight0 = (List<Long>) object;//TODO 拧紧枪测试。。。
//                        redLight0.add(ScrewId1);
//                        log.info("有红灯缓存，添加"+redLight0);
//                        CacheUtil.putInCache("redLight",redLight0);
//                    }
//
//                    map.put("alarmsTime", alarmsTime);
//
////                                    if(count <= 8) {
//                    screwTypeId1 = screwNum51List.get(count);
////                                    } else if (count >=9) {
////                                        count = screwNum52List.get(count + 1);
////                                    }
//
//                    LambdaQueryWrapper<screwType> queryWrapper = new LambdaQueryWrapper<>();
//                    queryWrapper.eq(screwType::getScrewId, screwTypeId1);
//                    queryWrapper.eq(screwType::getWeldingGunId, 51);
//                    screwType screwType = screwTypeMapper.selectOne(queryWrapper);
////                                    screwType screwType = screwTypeMapper.selectById(screwTypeId);
//
//                    map.put("screwType",screwType);
//
//                    map.put("ScrewId", ScrewId1);//null
//                    ScrewId1 ++;
//                    map.put("workPositionId", MessageConstant.workingPosition1);
//                    map.put("torque", 23456);
//                    map.put("unit", MessageConstant.torqueUnit);
//                    String json = JSON.toJSONString(map);
//                    log.info("json推消息重置前端红点1:"+json);
//                    webSocketServer.sendToAllClient(json);//推消息
//                    try {
//                        Thread.sleep(2000);//150
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
//                }
//
//                long ScrewId2 = 1;
//                int screwTypeId2;//, 13, 14, 15, 16, 9, 10, 11, 12
//                for (int count = 0; count <= 7; count++) {
//                    Map map = new HashMap();
//                    //清理前端的所有信息缓存红点等等
////                                    map.put("alert", -1);
//                    map.put("alert", 2);//全红
////                                    map.put("alert", 0);//全红
////                                    map.put("alert", 1);//全绿
//                    Object object = CacheUtil.getFromCache("redLight");
////                                    List<Long> redLight0;
//                    if (object == null){
//                        List<Long> redLight0 = new ArrayList<>();
//                        redLight0.add(ScrewId2);
//                        log.info("没有红灯缓存，新建"+redLight0);
//                        CacheUtil.putInCache("redLight",redLight0);
//                    }else {//如果有就加多一个
//                        List<Long> redLight0 = (List<Long>) object;//TODO 拧紧枪测试。。。
//                        redLight0.add(ScrewId2);
//                        log.info("有红灯缓存，添加"+redLight0);
//                        CacheUtil.putInCache("redLight",redLight0);
//                    }
//
//                    map.put("alarmsTime", alarmsTime);
//
////                                    if(count <= 8) {
//                    screwTypeId2 = screwNum51List.get(count);
////                                    } else if (count >=9) {
////                                        count = screwNum52List.get(count + 1);
////                                    }
//
//                    LambdaQueryWrapper<screwType> queryWrapper = new LambdaQueryWrapper<>();
//                    queryWrapper.eq(screwType::getScrewId, screwTypeId2);
//                    queryWrapper.eq(screwType::getWeldingGunId, 52);
//                    screwType screwType = screwTypeMapper.selectOne(queryWrapper);
////                                    screwType screwType = screwTypeMapper.selectById(screwTypeId);
//
//                    map.put("screwType",screwType);
//
//                    map.put("ScrewId", ScrewId2);//null
//                    ScrewId2 ++;
//                    map.put("workPositionId", MessageConstant.workingPosition1);
//                    map.put("torque", 23456);
//                    map.put("unit", MessageConstant.torqueUnit);
//                    String json = JSON.toJSONString(map);
//                    log.info("json推消息重置前端红点1:"+json);
//                    webSocketServer.sendToAllClient(json);//推消息
//                    try {
//                        Thread.sleep(2000);//150
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
//                }
//                //测试///////////////////////////////
////                                Object alarmsTime0 =  CacheUtil.getFromCache("alarmsTime");
////                                int alarmsTime = 0;
////                                if(alarmsTime0!=null){
////                                    alarmsTime = (int) alarmsTime0;
////                                }
////
////                                long ScrewId1 = 1;
////                                int screwTypeId1;//, 13, 14, 15, 16, 9, 10, 11, 12
//                                List<Integer> screwNum53List = Arrays.asList(1, 2);
//                                for (int count = 0; count <= 1; count++) {
//                                    Map map = new HashMap();
//                                    //清理前端的所有信息缓存红点等等
////                                    map.put("alert", -1);
////                                      map.put("alert", 2);//全红
////                                    map.put("alert", 0);//全红
//                                    map.put("alert", 1);//全绿
//                                    Object object = CacheUtil.getFromCache("redLight");
////                                    List<Long> redLight0;
//                                    if (object == null){
//                                        List<Long> redLight0 = new ArrayList<>();
//                                        redLight0.add(ScrewId1);
//                                        log.info("没有红灯缓存，新建"+redLight0);
//                                        CacheUtil.putInCache("redLight",redLight0);
//                                    }else {//如果有就加多一个
//                                        List<Long> redLight0 = (List<Long>) object;//TODO 拧紧枪测试。。。
//                                        redLight0.add(ScrewId1);
//                                        log.info("有红灯缓存，添加"+redLight0);
//                                        CacheUtil.putInCache("redLight",redLight0);
//                                    }
//
//                                    map.put("alarmsTime", alarmsTime);
//
////                                    if(count <= 8) {
//                                    screwTypeId1 = screwNum53List.get(count);
////                                    } else if (count >=9) {
////                                        count = screwNum52List.get(count + 1);
////                                    }
//
//                                    LambdaQueryWrapper<screwType> queryWrapper = new LambdaQueryWrapper<>();
//                                    queryWrapper.eq(screwType::getScrewId, screwTypeId1);
//                                    queryWrapper.eq(screwType::getWeldingGunId, 53);
//                                    screwType screwType = screwTypeMapper.selectOne(queryWrapper);
////                                    screwType screwType = screwTypeMapper.selectById(screwTypeId);
//
//                                    map.put("screwType",screwType);
//
//                                    map.put("ScrewId", ScrewId1);//null
//                                    ScrewId1 ++;
//                                    map.put("workPositionId", MessageConstant.workingPosition2);
//                                    map.put("torque", 23456);
//                                    map.put("unit", MessageConstant.torqueUnit);
//                                    String json = JSON.toJSONString(map);
//                                    log.info("json推消息重置前端红点2:"+json);
//                                    webSocketServer.sendToAllClient(json);//推消息
//                                    try {
//                                        Thread.sleep(2000);//150
//                                    } catch (InterruptedException e) {
//                                        throw new RuntimeException(e);
//                                    }
//                                }
//
////                                long ScrewId2 = 1;
////                                int screwTypeId2;//, 13, 14, 15, 16, 9, 10, 11, 12
//                                List<Integer> screwNum54List = Arrays.asList(1, 2);
//                                for (int count = 0; count <= 1; count++) {
//                                    Map map = new HashMap();
//                                    //清理前端的所有信息缓存红点等等
////                                    map.put("alert", -1);
////                                      map.put("alert", 2);//全红
////                                    map.put("alert", 0);//全红
//                                    map.put("alert", 1);//全绿
//                                    Object object = CacheUtil.getFromCache("redLight");
////                                    List<Long> redLight0;
//                                    if (object == null){
//                                        List<Long> redLight0 = new ArrayList<>();
//                                        redLight0.add(ScrewId1);
//                                        log.info("没有红灯缓存，新建"+redLight0);
//                                        CacheUtil.putInCache("redLight",redLight0);
//                                    }else {//如果有就加多一个
//                                        List<Long> redLight0 = (List<Long>) object;//TODO 拧紧枪测试。。。
//                                        redLight0.add(ScrewId1);
//                                        log.info("有红灯缓存，添加"+redLight0);
//                                        CacheUtil.putInCache("redLight",redLight0);
//                                    }
//
//                                    map.put("alarmsTime", alarmsTime);
//
////                                    if(count <= 8) {
//                                    screwTypeId2 = screwNum54List.get(count);
////                                    } else if (count >=9) {
////                                        count = screwNum52List.get(count + 1);
////                                    }
//
//                                    LambdaQueryWrapper<screwType> queryWrapper = new LambdaQueryWrapper<>();
//                                    queryWrapper.eq(screwType::getScrewId, screwTypeId2);
//                                    queryWrapper.eq(screwType::getWeldingGunId, 54);
//                                    screwType screwType = screwTypeMapper.selectOne(queryWrapper);
////                                    screwType screwType = screwTypeMapper.selectById(screwTypeId);
//
//                                    map.put("screwType",screwType);
//
//                                    map.put("ScrewId", ScrewId2);//null
//                                    ScrewId2 ++;
//                                    map.put("workPositionId", MessageConstant.workingPosition2);
//                                    map.put("torque", 23456);
//                                    map.put("unit", MessageConstant.torqueUnit);
//                                    String json = JSON.toJSONString(map);
//                                    log.info("json推消息重置前端红点2:"+json);
//                                    webSocketServer.sendToAllClient(json);//推消息
//                                    try {
//                                        Thread.sleep(2000);//150
//                                    } catch (InterruptedException e) {
//                                        throw new RuntimeException(e);
//                                    }
//                                }
//                //-----------------------------
//                webSocketServer.sendToAllClient(json0);//推消息
//
//
//                log.info("重建节点。。。");
//                //// 如果客户端创建成功，返回客户端实例，就会结束循环
//                client = OpcUaClient.create(ipProperties.getEndPointUrl(),
//                        //过滤可用的端点。
//                        // 它从服务器返回的端点列表中查找第一个安全策略为 None 的端点。
//                        // 这意味着这个客户端将使用不带安全性的连接方式。
//                        endpoints ->
//                                endpoints.stream()
//                                        .filter(e -> //不带安全性的连接（SecurityPolicy.None）
//                                                e.getSecurityPolicyUri()
//                                                        .equals(SecurityPolicy.None.getUri()))
//                                        .findFirst(),
//                        configBuilder ->
//                                configBuilder
//                                        .setApplicationName(LocalizedText.english
//                                                ("eclipse milo opc-ua client"))
//                                        //设置应用程序的 URI，通常用于标识客户端。
//                                        .setApplicationUri("urn:eclipse:milo:examples:client")
//                                        //设置身份提供者为 AnonymousProvider，
//                                        // 这意味着客户端将以匿名身份连接到服务器，不需要身份验证。
//                                        .setIdentityProvider(new AnonymousProvider())
//                                        //设置请求超时时间为 500 毫秒。
//                                        .setRequestTimeout(UInteger.valueOf(frequencyProperties.getNodeRequestTimeout()))
//                                        .build()
//                );
////                log.info("client是"+client);
//                return client;
//            } catch (UaException e) {
//                log.info("创建客户端异常");
////                if (client != null) {
////                    try {
////                        // 尝试关闭客户端以释放资源
////                        client.disconnect().get(); // 等待异步操作完成
////                    } catch (InterruptedException | ExecutionException e1) {
////                        e1.printStackTrace();
////                    }
////                }
//                Map map0 = new HashMap<>();
//                map0.put("car1Num", "PLC未连接");
//                map0.put("car1Type", "PLC未连接");
//                map0.put("repeat1",  "PLC未连接");
//                map0.put("car2Num", "PLC未连接");
//                map0.put("car2Type", "PLC未连接");
//                map0.put("repeat2", "PLC未连接");
//                String json0 = JSON.toJSONString(map0);
//                webSocketServer.sendToAllClient(json0);
////                waitTime = Math.min(waitTime + 500, MAX_WAIT_TIME);
////                asyncMessage.sendTest(waitTime, MAX_WAIT_TIME);
//                try {
//                    // 退避策略：每次重试后等待时间加倍，直到达到某个最大值
//                    waitTime = Math.min(waitTime + 500, MAX_WAIT_TIME);
////在协程中使用 Thread.sleep(waitTime); 是可以的，但这样做会阻塞当前线程，
//// 而不是仅仅挂起当前协程。
//                    Thread.sleep(waitTime);
//                    // 挂起当前协程一段时间后重试
////                    Strand.sleep(waitTime);
//                } catch (InterruptedException e1) {
//                    e1.printStackTrace();
//                }//释放
////                catch (SuspendExecution ex) {
////                    throw new RuntimeException(ex);
////                }
//
////                if (retryCount < maxRetry) {
////                    log.info("重连次数内"+retryCount);
////                    retryCount ++;
////                    Map map = new HashMap<>();
////                    map.put("message", "..创建OPC客户端失败，重连次数内..");
////                    String json = JSON.toJSONString(map);
////                    webSocketServer.sendToAllClient(json);
//////                    createClient();
////                }else {
//                    log.info("重试次数达到上限，停止重试");
//                    Map map = new HashMap<>();
//                    map.put("message", "..创建OPC客户端失败，请重启软件..");
//                    String json = JSON.toJSONString(map);
//                    webSocketServer.sendToAllClient(json);
//                    log.info(e.getMessage());
//                    e.printStackTrace();
////                    throw new RuntimeException(e);
////                }
//
//                //用无限循环代替递归，递归可能会导致栈溢出，而循环不会占用调用栈
////                retrySubscribe();
////            } else {
////                log.info("重试次数达到上限，停止重试");
////            }
//                //throw new RuntimeException(e);
//            } finally {
//                if (client != null) {
//                    client.disconnect().get(); // 确保客户端断开连接
//                }
//            }
////            return null;
//        }//while
//    }
//
////    @Async
////    public void sendTest() {
////        try {
////            // 退避策略：每次重试后等待时间加倍，直到达到某个最大值
////            waitTime = Math.min(waitTime + 500, MAX_WAIT_TIME);
////            Thread.sleep(waitTime);
////        } catch (InterruptedException e1) {
////            e1.printStackTrace();
////        }
////        Map map = new HashMap<>();
////        map.put("message", "..创建OPC客户端失败，重试..");
////        String json = JSON.toJSONString(map);
////        webSocketServer.sendToAllClient(json);
////    }
//
//
//    @Override
//    public String[] browseNode(OpcUaClient client, UaNode uaNode) {
//        List<? extends UaNode> nodes = null;
////        log.info("nodes0是"+nodes);
////        while (nodes == null) {
//            // 如果为 null，默认浏览对象文件夹
//            if (uaNode == null) {
//                try {
//                    nodes = client.getAddressSpace().browseNodes(Identifiers.ObjectsFolder);
////                    log.info("nodes2是"+nodes);
//                } catch (UaException e) {
//                    log.info("创建客户端异常1");
//                    retrySubscribe();
//                    log.info(e.getMessage());
//                    e.printStackTrace();
////                    throw new RuntimeException(e);
//                }
//            } else {
//                // 浏览指定节点的子节点
//                try {
//                    //TODO 处理网线断了抛出的异常
//                    // Failed to create Node from Reference to ExpandedNodeId{ns=2, id=111.222.carNum1, serverIndex=0}
//                    nodes = client.getAddressSpace().browseNodes(uaNode);
////                    log.info("nodes2是"+nodes);
//                } catch (UaException e) {
//                    log.info("创建客户端异常2");
//                    log.info(e.getMessage());
//                    e.printStackTrace();
////                    throw new RuntimeException(e);
//                }
//            }
////        }
//        // 用于存储 NodeId 的列表
//        List<String> nodeIds = new ArrayList<>();
//
//        // 遍历从浏览中得到的节点列表
//        for (UaNode nd : nodes) {
//            // 跳过系统性节点（名称以 "_" 开头）
//            String browseName = nd.getBrowseName().getName();
//            String nodeIdString = nd.getNodeId().toString(); // 获取节点 ID 的字符串表示
//            if (browseName.startsWith("_") || browseName.contains("示例")
//                    || browseName.contains("通道") || nodeIdString.contains("ns=0")) {
//                continue;
//            }
////             检查节点是否有有效的 ID
//            if (nd.getNodeId() != null) {
////                log.info("节点ID: " + nd.getNodeId()); // 打印节点ID
//                nodeIds.add(nd.getNodeId().toString()); // 将 NodeId 添加到列表中
//            }
//
//            // 递归调用，浏览当前节点的子节点
////            log.info("递归调用");
//            String[] childNodeIds = browseNode(client, nd);
//            if(childNodeIds != null && childNodeIds.length > 0){
////                log.info("childNodeIds2是："+ Arrays.toString(childNodeIds));
//                Collections.addAll(nodeIds, childNodeIds); // 添加子节点 ID
//            }
//        }
//        // 将 List 转换为数组并返回
//        return nodeIds.toArray(new String[0]);
//    }
//
//    //retrySubscribe 方法被声明为 synchronized，确保在多线程环境中，
//    // 只有一个线程可以执行这个方法，避免竞态条件。synchronized
//    //@Suspendable//可以让该方法在协程中暂停和恢复执行。这样可以简化异步编程，
//    // 提高代码的可读性和可维护性，并优化资源使用
//    //@Async//("asyncExecutor")
//    public void retrySubscribe() {
//        OpcUaClient client = null;
//        try {
//            log.info("重试订阅");
//            //等待释放资源???
//            try {
//                long WAIT_TIME = frequencyProperties.getPlcRetryTime();
////                Strand.sleep(WAIT_TIME);
//                Thread.sleep(WAIT_TIME);
//            } catch (InterruptedException e) {
//                log.info(e.getMessage());
//                e.printStackTrace();
//            }
//            //确保在读写之前 创建好这个连接
//            client = opcUaService.createClient();
//            if(client == null){
//                log.info("失败数量达到极限");
//                Map map = new HashMap<>();
//                map.put("message", "··已达到最大重连次数1，请重启软件··");
//                String json = JSON.toJSONString(map);
//                webSocketServer.sendToAllClient(json);
//                jSerialCommIOService.buzzerControl();
//                return;
//            }
//
//            client.connect().get();
//            String[] nodeIds = opcUaService.browseNode(client, null);
//            log.info("重试订阅检测到的可用节点: " + Arrays.toString(nodeIds));
//
//            // 使用列表手动将 NodeId 逐个添加到新节点数组
//            // 这里的 list 用于临时保存动态添加的 NodeId 对象
//            List<String> nodeIdList = new ArrayList<>();
//            String nodeString = Arrays.toString(nodeIds);
//            String carNum = carNodeProperties.getCarNum();
//            String carType = carNodeProperties.getCarType();
//            String repeat = carNodeProperties.getRepeat();
//            boolean containsNull1 = nodeString.contains(carNum);
//            boolean containsNull2 = nodeString.contains(carType);
//            boolean containsNull3 = nodeString.contains(repeat);
////            log.info("nodeIds1是"+ Arrays.toString(nodeIds));
//            if (nodeIds != null && containsNull1 && containsNull2 && containsNull3) {
//                log.info("nodeIds2是"+ Arrays.toString(nodeIds));
////                for (String nodeId : nodeIds) {
////                    // 打印每个 NodeId
//////                log.info("处理 NodeId: " + nodeId);
////                    // 将每个 NodeId 添加到 List 中
////                    nodeIdList.add(nodeId); // 添加到列表
////                }
//                nodeIdList.addAll(Arrays.asList(nodeIds));
//
////                Map map = new HashMap<>();
////                map.put("message", "...创建OPC客户端成功...");
////                String json = JSON.toJSONString(map);
////                webSocketServer.sendToAllClient(json);
//            } else {
//                log.info("nodeIds为空，或者检测不到相关节点，释放资源。。。");
//                try {
//                    client.disconnect().get();
////                        jSerialCommIOService.yellowUp();
//                    Map<String, String> map0 = new HashMap<>();
//                    map0.put("car1Num", "PLC重连中");
//                    map0.put("car1Type", "PLC重连中");
//                    map0.put("repeat1", "PLC重连中");
//                    map0.put("standard1min", "");
//                    map0.put("standard1max", "");
//                    CacheUtil.removeFromCache("standard1");
//                    //CacheUtil.removeFromCache("standard1max");
//                    map0.put("car2Num", "PLC重连中");
//                    map0.put("car2Type", "PLC重连中");
//                    map0.put("repeat2", "PLC重连中");
//                    map0.put("standard2min", "");
//                    map0.put("standard2max", "");
//                    CacheUtil.removeFromCache("standard2");
//                    //CacheUtil.removeFromCache("standard2max");
//                    //把map转为json
//                    String json0 = JSON.toJSONString(map0);
//                    log.info("plc已断开的json是"+json0);
////                    webSocketServer.sendToAllClient(json0);//推消息
//
//                } catch (Exception e0) {
//                    log.info("关闭客户端时发生异常: " + e0.getMessage());
//                }
//                retrySubscribe();
//            }
//            opcUaService.subscribe(client, nodeIdList);
//        } catch (Exception e) {
//            log.info("catch抛出异常");
//            if (client != null) {
//                log.info("catch释放资源");
//                try {
//                    client.disconnect().get();
//                } catch (Exception e1) {
//                    log.info("关闭客户端时发生异常: " + e1.getMessage());
//                }
//            }
//            log.info(e.getMessage());
//            e.printStackTrace();
////            retrySubscribe();//不能在throw中循环调用retrySubscribe()
////            throw new RuntimeException(e);
//        } finally {
//// 确保在方法结束时释放资源
//            if (client != null) {
//                log.info("finally释放资源");
//                try {
//                    client.disconnect().get();
//                } catch (Exception e2) {
//                    log.info("关闭客户端时发生异常: " + e2.getMessage());
//                }
//            }
//        }
//    }
//
//    @Override
//    public int subscribe(OpcUaClient client, List<String> nodeIds) throws Exception {
////        SimpleCache cache = new SimpleCache();
//        AtomicInteger atomicId = new AtomicInteger();
//
//        Map<NodeId, Object> monitoredValues = new HashMap<>();
//
//        client
//                .getSubscriptionManager()
//                //订阅频率//MessageConstant.monitorNodeFrequency
//                .createSubscription(frequencyProperties.getMonitorNodeFrequency())
//                .thenAccept(subscription -> {
//                    List<MonitoredItemCreateRequest> requests = new ArrayList<>();
//
//                    for (String nodeId : nodeIds) {
////                        log.info("nodeId是"+nodeId);
//                        // 解析 NodeId
//                        String[] parts = nodeId.replace("NodeId{", "").replace("}", "").split(", ");
//                        String namespace = parts[0].split("=")[1]; // 获取 ns= 的值
//                        String id = parts[1].split("=")[1]; // 获取 id= 的值
//
//                        // 构建目标格式的字符串，注意使用 s= 来表示字符串 ID
//                        String formattedNodeId = "ns=" + namespace + ";s=" + id; // 使用 s= 表示字符串类型的 NodeId
//
//                        // 将目标格式字符串转换为 NodeId 对象
//                        NodeId nodeId0 = NodeId.parse(formattedNodeId); // 解析字符串为 NodeId
////                        log.info("格式化节点后"+nodeId0);
//                        // 创建 ReadValueId
//                        ReadValueId readValueId = new ReadValueId(nodeId0, AttributeId.Value.uid(),
//                                null, null);
//
//                        // 创建监控的参数
//                        MonitoringParameters parameters = new MonitoringParameters(
//                                UInteger.valueOf(atomicId.getAndIncrement()), // 生成唯一的监控参数 ID
//                                (double) frequencyProperties.getMonitorNodeFrequency(), //MessageConstant.monitorNodeFrequency                                      // 更新间隔
//                                null,                                         // 最大通知时间
//                                UInteger.valueOf(15),                         // 最大通知数量
//                                true                                           // 使用数据变化的通知
//                        );
//
//                        // 创建监控项请求
//                        MonitoredItemCreateRequest request = new MonitoredItemCreateRequest(readValueId, MonitoringMode.Reporting, parameters);
//                        requests.add(request);  // 将请求添加到列表中
//                    }
//
//                    // 创建监控项，并且注册变量值改变时的回调函数
//                    subscription.createMonitoredItems(
//                            TimestampsToReturn.Both,
//                            requests,
//                            (item, id) -> item.setValueConsumer((it, val) -> {
//                                // 获取节点 ID 和新值
//                                NodeId monitoredNodeId = it.getReadValueId().getNodeId();
//                                Object newValue = val.getValue().getValue();
//
//                                // 将新值存储到 Map 中
//                                monitoredValues.put(monitoredNodeId, newValue);
//
//                                // 打印输出监控到的值
////                                log.info("节点: " + monitoredNodeId);
////                                log.info("值: " + newValue);
//                            })
//                    );
//
//                    //报警次数统计
//                    Object alarmsTime = CacheUtil.getFromCache("alarmsTime");
////            log.info("alarmsTime是"+alarmsTime);
//                    if(alarmsTime == null){
//                        log.info("新建报警统计缓存");
//                        LambdaQueryWrapper<CarStatus> queryWrapper = new LambdaQueryWrapper<>();
//                        //匹配扭力不是正常的以及是待处理的告警
//                        queryWrapper.ne(CarStatus::getAlarmLevel, CarStatus.AlarmLevel.normal)
//                                .eq(CarStatus::getCheckStatus, CarStatus.CheckStatus.waitForCheck);
//                        //只匹配今天的
//                        LocalDate today = LocalDate.now();
//                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//                        String todayStr = today.format(formatter);
//                        queryWrapper.like(CarStatus::getCreateTime, todayStr);
//                        int count = carStatusMapper.selectCount(queryWrapper);
//                        CacheUtil.putInCache("alarmsTime",count);
//                    }
//
//                    // 每秒将监控到的数据缓存起来
//                    Timer timer = new Timer();
//                    timer.scheduleAtFixedRate(new TimerTask() {
//                         //用于储存监控的值，用于与下一次监控到的值进行比较
//                        // 设定最大重试次数
//                        final int maxRetries = frequencyProperties.getPlcRetryFrequency();
////                        final int maxRetries0 = 5;
//                        int attempts = 0;//plc一开始就断开的尝试重连机会
//                        //弹窗次数
//                        int alertTime = 1;
//                        //
////                        int cacheTime = 1;
////                        int attempts0 = 0;//plc工作中突然断开的尝试重连机会
//                        @Override
//                        public void run() {
//                            // 返回监控值的逻辑
//                            Map<String, String> i = null;
////                            try {
//                                //TODO 测试
//                                //检查有没有红灯缓存，如果没有就新建一个
////                                Object object = CacheUtil.getFromCache("redLight");
////                                if (object == null){
////                                    log.info("新建--");
////                                    List<Long> redLight = new ArrayList<>();
////                                    redLight.add(Long.valueOf("121"));
////                                    CacheUtil.putInCache("redLight",redLight);
////                                }else {//如果有就加多一个
////                                    log.info("已有--");
////                                    //Object object = CacheUtil.getFromCache("redLight");
////                                    List<Long> redLight = (List<Long>) object;//TODO 拧紧枪测试。。。
////                                    redLight.add(Long.valueOf("212"));
////                                    CacheUtil.putInCache("redLight",redLight);
////                                }
//
//                                i = sendToFrontEnd(monitoredValues);
////                                log.info("i是什么"+i);
////                            }
////                            catch (Exception e) {
//////                                retrySubscribe();
////
//////                                Map map = new HashMap();
//////                                map.put("message", "··已达到最大重连次数，请重启软件··");
//////                                String json = JSON.toJSONString(map);
//////                                webSocketServer.sendToAllClient(json);
////                                log.info("重连????");
////                                e.printStackTrace();// 打印错误信息，但不会中断程序
//////                                throw new RuntimeException(e);
////                            }
//                            if (i == null) {//plc断开
//                                attempts = attempts + 1;
//                                // 没有监控到数据，取消当前任务并立即跳到下一个监控
//                                log.info("监控数据为空，立即跳到下一个周期，plc初次连接，给了{}次机会",attempts);
//
//                                if(attempts >= maxRetries){//>=
////                                    try {
////                                    jSerialCommIOService.greenOut();
////                                        //蜂鸣器响5秒
////                                        jSerialCommIOService.buzzerControl();
//                                        jSerialCommIOService.redUp();
//                                        log.info("重连?------------------?");
////                                        Map map = new HashMap();
////                                        map.put("message", "··PLC连接失败，重连中··");
////                                        String json = JSON.toJSONString(map);
////                                        webSocketServer.sendToAllClient(json);
//
//                                        retrySubscribe();
////                                    } catch (Exception e) {
////                                        log.info("重连???");
////                                        retrySubscribe();
////                                        throw new RuntimeException(e);
////                                    }
//                                }
//                                return;
//                            }else {
//                                if (alertTime == 1){
//                                    //红灯灭
////                                    jSerialCommIOService.redOut();
//                                    //绿灯亮
//                                    jSerialCommIOService.greenUp();
//                                    Map map = new HashMap();
//                                    map.put("message", "····PLC连接成功····");
//                                    String json = JSON.toJSONString(map);
//                                    webSocketServer.sendToAllClient(json);
//                                    alertTime = alertTime -1;
//                                }
//                            }
//                            //监控拿到的
////                            String car1Num = i.get("car1Num").trim();
////                            String car1Type = i.get("car1Type").trim();
////                            String repeat1 = i.get("repeat1").trim();
////                            String car2Num = i.get("car2Num").trim();
////                            String car2Type = i.get("car2Type").trim();
////                            String repeat2 = i.get("repeat2").trim();
//
////                            LocalDate today = LocalDate.now();
////                            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
////                            String todayStr = today.format(formatter);
////                            LambdaQueryWrapper<CarNumPrefix> queryWrapper = new LambdaQueryWrapper<>();
////                            queryWrapper.like(CarNumPrefix::getCreateTime, todayStr);
////                            int carNumPrefixCount = carNumPrefixMapper.selectCount(queryWrapper);
////                            CarNumPrefix carNumPrefix = null;
////                            if(carNumPrefixCount == 1){
////                                carNumPrefix = carNumPrefixMapper.selectOne(queryWrapper);
////                            }else if(carNumPrefixCount > 1){
////                                log.info("数据库存在多个车身号前缀");
////                                Map map = new HashMap();
////                                map.put("message", "..存在多个车身号前缀，请联系管理员..");
////                                String json = JSON.toJSONString(map);
////                                webSocketServer.sendToAllClient(json);
////                            }
//
//                            //缓存拿到的
//                            String car1NumCache = (String) CacheUtil.getFromCache("carNum1");
//                            car1NumCache = (car1NumCache != null && !car1NumCache.isEmpty()) ? car1NumCache : "";
//                            String car1TypeCache = (String) CacheUtil.getFromCache("carType1");
//                            car1TypeCache = (car1TypeCache != null && !car1TypeCache.isEmpty()) ? car1TypeCache : "";
//                            String repeat1Cache = (String) CacheUtil.getFromCache("repeat1");
//                            repeat1Cache = (repeat1Cache != null && !repeat1Cache.isEmpty()) ? repeat1Cache : "";
//                            String car2NumCache = (String) CacheUtil.getFromCache("carNum2");
//                            car2NumCache = (car2NumCache != null && !car2NumCache.isEmpty()) ? car2NumCache : "";
//                            String car2TypeCache = (String) CacheUtil.getFromCache("carType2");
//                            car2TypeCache = (car2TypeCache != null && !car2TypeCache.isEmpty()) ? car2TypeCache : "";
//                            String repeat2Cache = (String) CacheUtil.getFromCache("repeat2");
//                            repeat2Cache = (repeat2Cache != null && !repeat2Cache.isEmpty()) ? repeat2Cache : "";
//
//
//                            String car1Type = (i.get("car1Type") != null && !i.get("car1Type").isEmpty()) ?
//                                    i.get("car1Type").trim() : "";
//                            String repeat1 = (i.get("repeat1") != null && !i.get("repeat1").isEmpty()) ?
//                                    i.get("repeat1").trim() : "";
//                            String car1Num = (i.get("car1Num") != null && !i.get("car1Num").isEmpty()) ?
//                                    i.get("car1Num").trim() : "";
//                            log.info("当前车1是"+car1Num.trim()+"-"+car1Type.trim()+"-"+repeat1.trim());
//
//
//                            //应该在这里处理
////                            String car1Num = null;
////
////                            //如果从plc里获取得到车身号，就用plc的车身号，否则用数据库里的前缀
////                            if(!i.get("car1Num").trim().isEmpty()){
////                                log.info("用plc的车身号");
////                                //用plc的车身号
////                                car1Num = i.get("car1Num").trim();
////                            }else if(carNumPrefix != null){
////                                 log.info("用数据库的车身号前缀");
////                                //用数据库里的前缀和连番进行拼接，构建车身号
////                                try {
////                                    //TODO 假如i.get("repeat1").trim()是01，repeat1会变成1
////                                    int repeat1Int = 0;
////                                    if(!repeat1.trim().isEmpty() && repeat1.trim().matches("-?\\d+")) {
////                                        log.info("repeat1是数字");
////                                        repeat1Int = Integer.parseInt(repeat1);
////                                    }else {
////                                        log.info("repeat1不是数字");
////                                        Thread.sleep(12000);
////                                        Map map = new HashMap();
////                                        map.put("message","..车身工位的连番必须是数字..");
////                                        String json = JSON.toJSONString(map);
////                                        webSocketServer.sendToAllClient(json);
////                                    }
////
//////                                    int repeat1Int = Integer.parseInt(repeat1);
////                                    //如果连番号(当前检测到的车!=前一辆车+1)不连续，就说明工位插入了一辆新车(他有自己的连番号)，需要给这辆车的车身号的前三位数设置为空字符串---
////                                    //加多一个前一个是99的，当前不是00的，则说明是插入了车，需要给车设置新的车身号前缀
////                                    //需要排除掉车被抽出的情况，连番从1到3的情况，从99到1的情况
////                                    int IntRepeat1Cache;
////                                    if (!repeat1Cache.equals("") && !repeat1Cache.isEmpty() && repeat1Cache.matches("-?\\d+")) {
////                                        log.info("repeat1Cache是数字");
////                                        IntRepeat1Cache = Integer.parseInt(repeat1Cache);
////                                    } else {
////                                        log.info("repeat1Cache不是数字");
////                                        IntRepeat1Cache = 0;
////                                    }
////
//////                                    int IntRepeat1Cache = Integer.parseInt(repeat1Cache);
////                                    //连番号不连续条件
////                                     if((repeat1Int != (IntRepeat1Cache + 1) ||//!Integer.toString(repeat1).equals("00")
////                                             (IntRepeat1Cache == 99 && repeat1Int != 0))
////                                             //上两个只要一个成立，就可以证明 连番号不连续
////                                             &&
////                                             //下面两个，一个排除掉车被抽出连番从1到3的情况，
////                                             // 一个排除掉车被抽出连番从99到1的情况
////                                             !(repeat1Int == (IntRepeat1Cache + 2)) &&
////                                             !(IntRepeat1Cache == 99 && repeat1Int == 1)){
////                                         log.info("99 0情况");
////                                         car1Num = formatToYYMMDD(todayStr) + repeat1;//today
////                                         log.info("car1Num是"+ car1Num);
////                                     }
////
////                                     //repeat1Cache是上一个连番号，repeat1是当前检测到的连番号
////                                    //Integer.toString(repeat1).equals("00")
////                                     else if(repeat1Int == 0 && IntRepeat1Cache == 99){//说明连番号经过了一个轮回，车身号前缀需要加一
////                                         log.info("0 99情况");
////                                          car1Num = (Integer.parseInt(carNumPrefix.getCarNum()) + 1) + repeat1;
////                                         log.info("car1Num是"+ car1Num);
////                                         //TODO 是repeat他自己变回0还是.。。
////                                     }else {//正常情况（拼接）
////                                         log.info("正常情况（拼接）");
////                                         car1Num = carNumPrefix.getCarNum() + repeat1;
////                                         log.info("car1Num是"+ car1Num);
////                                     }
////                                   } catch (NumberFormatException e) {
////                                    log.info("车身号和连番号强转拼接数据转换异常");
////                                    e.printStackTrace();
////                                   } catch (InterruptedException e) {
////                                    throw new RuntimeException(e);
////                                }
////                            }
//
//
//                            String car2Type = (i.get("car2Type") != null && !i.get("car2Type").isEmpty()) ?
//                                    i.get("car2Type").trim() : "";
//                            String repeat2 = (i.get("repeat2") != null && !i.get("repeat2").isEmpty()) ?
//                                    i.get("repeat2").trim() : "";
//                            String car2Num = (i.get("car2Num") != null && !i.get("car2Num").isEmpty()) ?
//                                    i.get("car2Num").trim() : "";
//                            log.info("当前车2是"+car2Num.trim()+"-"+car2Type.trim()+"-"+repeat2.trim());
//
////                            String car2Num = null;
//
//                            //如果从plc里获取得到车身号，就用plc的车身号，否则用数据库里的前缀
////                            if(!i.get("car2Num").trim().isEmpty()){
////                                //用plc的车身号
////                                car2Num = i.get("car2Num").trim();
////                            }else if(carNumPrefix != null){
////                                //用数据库里的前缀和连番进行拼接，构建车身号
////                                try {
////                                    //TODO 假如i.get("repeat2").trim()是01，repeat2会变成1
////                                    int repeat2Int = 0;
////                                    if(!repeat2.trim().isEmpty() && repeat2.trim().matches("-?\\d+")) {
////                                        repeat2Int = Integer.parseInt(repeat2);
////                                    }
////
//////                                    int repeat2Int = Integer.parseInt(repeat2);
////                                    //如果连番号(当前检测到的车!=前一辆车+1)不连续，就说明工位插入了一辆新车(他有自己的连番号)，需要给这辆车的车身号的前三位数设置为空字符串---
////                                    //加多一个前一个是99的，当前不是00的，则说明是插入了车，需要给车设置新的车身号前缀
////                                    //需要排除掉车被抽出的情况，连番从1到3的情况，从99到1的情况
//////                                    int IntRepeat2Cache = Integer.parseInt(repeat2Cache);
////                                    int IntRepeat2Cache;
////                                    if (!repeat2Cache.equals("") && !repeat2Cache.isEmpty() && repeat2Cache.matches("-?\\d+")) {
////                                        IntRepeat2Cache = Integer.parseInt(repeat2Cache);
////                                    } else {
////                                        IntRepeat2Cache = 0;
////                                    }
////
////                                    //连番号不连续条件
////                                    if((repeat2Int != (IntRepeat2Cache + 1) ||//!Integer.toString(repeat2).equals("00")
////                                            (IntRepeat2Cache == 99 && repeat2Int != 0))
////                                            //上两个只要一个成立，就可以证明 连番号不连续
////                                            &&
////                                            //下面两个，一个排除掉车被抽出连番从1到3的情况，
////                                            // 一个排除掉车被抽出连番从99到1的情况
////                                            !(repeat2Int == (IntRepeat2Cache + 2)) &&
////                                            !(IntRepeat2Cache == 99 && repeat2Int == 1)){
////
////                                        car2Num = formatToYYMMDD(todayStr) + repeat2;//today
////                                    }
////
////                                    //repeat2Cache是上一个连番号，repeat2是当前检测到的连番号
////                                    //Integer.toString(repeat2).equals("00")
////                                    else if(repeat2Int == 0 && IntRepeat2Cache == 99){//说明连番号经过了一个轮回，车身号前缀需要加一
////                                        car2Num = (Integer.parseInt(carNumPrefix.getCarNum()) + 1) + repeat2;
////                                        //TODO 是repeat他自己变回0还是.。。
////                                    }else {//正常情况（拼接）
////                                        car2Num = carNumPrefix.getCarNum() + repeat2;
////                                    }
////                                } catch (NumberFormatException e) {
////                                    log.info("车身号和连番号强转拼接数据转换异常");
////                                    e.printStackTrace();
////                                }
////                            }
//
//
//                            //缓存拿到的
////                            String car1NumCache = (String) CacheUtil.getFromCache("carNum1");
////                            car1NumCache = (car1NumCache != null && !car1NumCache.isEmpty()) ? car1NumCache : "";
////                            String car1TypeCache = (String) CacheUtil.getFromCache("carType1");
////                            car1TypeCache = (car1TypeCache != null && !car1TypeCache.isEmpty()) ? car1TypeCache : "";
////                            String repeat1Cache = (String) CacheUtil.getFromCache("repeat1");
////                            repeat1Cache = (repeat1Cache != null && !repeat1Cache.isEmpty()) ? repeat1Cache : "";
////                            String car2NumCache = (String) CacheUtil.getFromCache("carNum2");
////                            car2NumCache = (car2NumCache != null && !car2NumCache.isEmpty()) ? car2NumCache : "";
////                            String car2TypeCache = (String) CacheUtil.getFromCache("carType2");
////                            car2TypeCache = (car2TypeCache != null && !car2TypeCache.isEmpty()) ? car2TypeCache : "";
////                            String repeat2Cache = (String) CacheUtil.getFromCache("repeat2");
////                            repeat2Cache = (repeat2Cache != null && !repeat2Cache.isEmpty()) ? repeat2Cache : "";
//
//                            //TODO ----------------------分割
//
//
////                            log.info("car1NumCache是:"+car1NumCache);
//
////                            String car1TypeCache = "";
////                            car1TypeCache = (String) CacheUtil.getFromCache("carType1");
////                            String repeat1Cache = "";
////                            repeat1Cache = (String) CacheUtil.getFromCache("repeat1");
////                            String car2NumCache = "";
////                            car2NumCache = (String) CacheUtil.getFromCache("carNum2");
////                            String car2TypeCache = "";
////                            car2TypeCache = (String) CacheUtil.getFromCache("carType2");
////                            String repeat2Cache = "";
////                            repeat2Cache = (String) CacheUtil.getFromCache("repeat2");
//                            //与上一次监控到的值进行比较
////                            log.info("缓存1是:"+car1NumCache);
////                            log.info("监控到的是:"+car1Num);
//
////                            if(car1Num.equals("") &&
////                                    car1Type.equals("") &&
////                                    repeat1.equals("") &&
////                                    car2Num.equals("") &&
////                                    car2Type.equals("") &&
////                                    repeat2.equals("")){
////                                log.info("PLC断开重连");
////                                Map<String, String> map0 = new HashMap<>();
////                                map0.put("car1Num", "PLC已断开");
////                                map0.put("car1Type", "PLC已断开");
////                                map0.put("repeat1",  "PLC已断开");
////                                map0.put("car2Num",  "plc已断开");
////                                map0.put("car2Type", "plc已断开");
////                                map0.put("repeat2",  "plc已断开");
////                                //把map转为json
////                                String json0 = JSON.toJSONString(map0);
////                                log.info("车的json是"+json0);
////                                webSocketServer.sendToAllClient(json0);//推消息
////                                try {
////                                    attempts0 = attempts0 + 1;
////                                    log.info("plc工作中突然断开，给了{}次机会",attempts0);
////                                    //Thread.sleep(frequencyProperties.getMonitorNodeFrequency());
////                                    if(attempts0 >= maxRetries0) {
////                                        retrySubscribe();
////                                    }
////                                } catch (Exception e) {
////                                    throw new RuntimeException(e);
////                                }
////                                Map map = new HashMap();
////                                map.put("message", "····PLC已断开，重连中····");
////                                map.put("torque", ""); //扭力值是
////                                map.put("unit", "");
////                                String json = JSON.toJSONString(map);
////                                webSocketServer.sendToAllClient(json);//推消息
////                            }else if(car1Num.equals("") &&
////                                    car1Type.equals("") &&
////                                    repeat1.equals("") &&
////                                    !car2Num.equals("") &&
////                                    !car2Type.equals("") &&
////                                    !repeat2.equals("")){
////                                log.info("只是工位一没有数据，PLC不用重连");
////                                Map<String, String> map0 = new HashMap<>();
////                                map0.put("car1Num", "无数据");
////                                map0.put("car1Type",  "无数据");
////                                map0.put("repeat1",  "无数据");
//////                                    map0.put("car2Num",  "plc已断开");
//////                                    map0.put("car2Type", "plc已断开");
//////                                    map0.put("repeat2",  "plc已断开");
////                                //把map转为json
////                                String json0 = JSON.toJSONString(map0);
////                                log.info("车的json是"+json0);
////                                webSocketServer.sendToAllClient(json0);//推消息
////                                try {
////                                    Thread.sleep(frequencyProperties.getMonitorNodeFrequency());
//////                                    retrySubscribe();
////                                } catch (Exception e) {
////                                    throw new RuntimeException(e);
////                                }
//////                                Map map = new HashMap();
//////                                map.put("message", "····PLC已断开，尝试重连····");
//////                                map.put("torque", ""); //扭力值是
//////                                map.put("unit", "");
//////                                String json = JSON.toJSONString(map);
//////                                webSocketServer.sendToAllClient(json);//推消息
////                            } else if(!car1Num.equals("") &&
////                                    !car1Type.equals("") &&
////                                    !repeat1.equals("") &&
////                                    car2Num.equals("") &&
////                                    car2Type.equals("") &&
////                                    repeat2.equals("")) {
////                                log.info("只是工位二没有数据，PLC不用重连");
////                                Map<String, String> map0 = new HashMap<>();
////                                map0.put("car1Num", "无数据");
////                                map0.put("car1Type",  "无数据");
////                                map0.put("repeat1",  "无数据");
//////                                    map0.put("car2Num",  "plc已断开");
//////                                    map0.put("car2Type", "plc已断开");
//////                                    map0.put("repeat2",  "plc已断开");
////                                //把map转为json
////                                String json0 = JSON.toJSONString(map0);
////                                log.info("车的json是"+json0);
////                                webSocketServer.sendToAllClient(json0);//推消息
////                                try {
////                                    Thread.sleep(frequencyProperties.getMonitorNodeFrequency());
//////                                    retrySubscribe();
////                                } catch (Exception e) {
////                                    throw new RuntimeException(e);
////                                }
//////                                Map map = new HashMap();
//////                                map.put("message", "····PLC已断开，尝试重连····");
//////                                map.put("torque", ""); //扭力值是
//////                                map.put("unit", "");
//////                                String json = JSON.toJSONString(map);
//////                                webSocketServer.sendToAllClient(json);//推消息
////                            }
//
////                            log.info("缓存1是:"+car1NumCache);
////                            log.info("监控到的是:"+car1Num);
////                            log.info("缓存1是:"+car1TypeCache);
////                            log.info("监控到的是:"+car1Type);
////                            log.info("缓存1是:"+repeat1Cache);
////                            log.info("监控到的是:"+repeat1);
//
//                            if((car1NumCache.isEmpty() &&
//                                    car1TypeCache.isEmpty() &&
//                                    repeat1Cache.isEmpty())
//                                    ||
//                               (car2NumCache.isEmpty() &&
//                                       car2TypeCache.isEmpty() &&
//                                       repeat2Cache.isEmpty())) {
//                                retryAndNoData(car1Num, car1Type, repeat1,
//                                        car2Num, car2Type, repeat2);
//                            }
//
//                            if (car1NumCache.equals(car1Num) &&
//                                    car1TypeCache.equals(car1Type) &&
//                                    repeat1Cache.equals(repeat1)) {
//                                // 与上一次监控到的值相同，取消当前任务并立即跳到下一个周期
//                                log.info("与上一次监控到的car1值相同，等待跳到下一个周期.");
//                            }else {//防止plc断开的时候也清理前端的告警点
//                                //清理工位一的扭力标准缓存
//                                CacheUtil.removeFromCache("standard1");
//                                //CacheUtil.removeFromCache("standard1max");
////                                CacheUtil.removeFromCache("standard2");
//                                //else if(!car1Num.isEmpty() && !car1Type.isEmpty() && !repeat1.isEmpty())
//                                // 与上一次监控到的值不同，继续监控下一次
//                                log.info("与上一次监控到的car1值不同，缓存以及保存当前车的信息，让心跳端读取");
//                                //更新缓存
//                                CacheUtil.putInCache("carNum1", car1Num.trim());
//                                CacheUtil.putInCache("carType1", car1Type.trim());
//                                CacheUtil.putInCache("repeat1", repeat1.trim());
//                                //无论之前是否是红灯，清理红灯缓存并统统绿灯
////                                List<Long> redLight = new ArrayList<>();
////                                CacheUtil.putInCache("redLight", redLight);
//////                                CacheUtil.removeFromCache("redLight");
////                                jSerialCommIOService.greenUp();
//                                //清理前端的螺丝缓存
//                                for (int count = 1; count <= 16; count++) {
//                                    CacheUtil.removeFromCache("screw"+ count);
////                                    CacheUtil.putInCache("screw"+ count, null);
////                                    CacheUtil.putInCache("screw"+ count, 0.00); // 也可以用 null
//                                }
////--------------------------------------------------------------------------
//                                Object alarmsTime0 =  CacheUtil.getFromCache("alarmsTime");
//                                int alarmsTime = 0;
//                                if(alarmsTime0!=null){
//                                    alarmsTime = (int) alarmsTime0;
//                                }
//
//
//                                long ScrewId1 = 1;
//                                int screwTypeId1;//5, 6, 8, 7, 2, 1, 3, 4, 13, 14, 15, 16, 9, 10, 11, 12
//                                List<Integer> screwNum51List = Arrays.asList(5, 6, 7, 8, 1, 2, 3, 4);
//                                for (int count = 0; count <= 7; count++) {
//                                    Map map = new HashMap();
//                                    //清理前端的所有信息缓存红点等等
////                                    map.put("alert", -1);
////                                      map.put("alert", 2);//全红
////                                    map.put("alert", 0);//全红
//                                    map.put("alert", 1);//全绿
//                                    Object object = CacheUtil.getFromCache("redLight");
////                                    List<Long> redLight0;
//                                    if (object == null){
//                                        List<Long> redLight0 = new ArrayList<>();
//                                        redLight0.add(ScrewId1);
//                                        log.info("没有红灯缓存，新建"+redLight0);
//                                        CacheUtil.putInCache("redLight",redLight0);
//                                    }else {//如果有就加多一个
//                                        List<Long> redLight0 = (List<Long>) object;//TODO 拧紧枪测试。。。
//                                        redLight0.add(ScrewId1);
//                                        log.info("有红灯缓存，添加"+redLight0);
//                                        CacheUtil.putInCache("redLight",redLight0);
//                                    }
//
//                                    map.put("alarmsTime", alarmsTime);
//
////                                    if(count <= 8) {
//                                    screwTypeId1 = screwNum51List.get(count);
////                                    } else if (count >=9) {
////                                        count = screwNum52List.get(count + 1);
////                                    }
//
//                                    LambdaQueryWrapper<screwType> queryWrapper = new LambdaQueryWrapper<>();
//                                    queryWrapper.eq(screwType::getScrewId, screwTypeId1);
//                                    queryWrapper.eq(screwType::getWeldingGunId, 51);
//                                    screwType screwType = screwTypeMapper.selectOne(queryWrapper);
////                                    screwType screwType = screwTypeMapper.selectById(screwTypeId);
//
//                                    map.put("screwType",screwType);
//
//                                    map.put("ScrewId", ScrewId1);//null
//                                    ScrewId1 ++;
//                                    map.put("workPositionId", MessageConstant.workingPosition1);
//                                    map.put("torque", 23456);
//                                    map.put("unit", MessageConstant.torqueUnit);
//                                    String json = JSON.toJSONString(map);
//                                    log.info("json推消息重置前端红点1:"+json);
//                                    webSocketServer.sendToAllClient(json);//推消息
//                                    try {
//                                        Thread.sleep(2000);//150
//                                    } catch (InterruptedException e) {
//                                        throw new RuntimeException(e);
//                                    }
//                                }
//
//                                long ScrewId2 = 1;
//                                int screwTypeId2;//, 13, 14, 15, 16, 9, 10, 11, 12
//                                for (int count = 0; count <= 7; count++) {
//                                    Map map = new HashMap();
//                                    //清理前端的所有信息缓存红点等等
////                                    map.put("alert", -1);
//                                    map.put("alert", 2);//全红
////                                    map.put("alert", 0);//全红
////                                    map.put("alert", 1);//全绿
//                                    Object object = CacheUtil.getFromCache("redLight");
////                                    List<Long> redLight0;
//                                    if (object == null){
//                                        List<Long> redLight0 = new ArrayList<>();
//                                        redLight0.add(ScrewId2);
//                                        log.info("没有红灯缓存，新建"+redLight0);
//                                        CacheUtil.putInCache("redLight",redLight0);
//                                    }else {//如果有就加多一个
//                                        List<Long> redLight0 = (List<Long>) object;//TODO 拧紧枪测试。。。
//                                        redLight0.add(ScrewId2);
//                                        log.info("有红灯缓存，添加"+redLight0);
//                                        CacheUtil.putInCache("redLight",redLight0);
//                                    }
//
//                                    map.put("alarmsTime", alarmsTime);
//
////                                    if(count <= 8) {
//                                    screwTypeId2 = screwNum51List.get(count);
////                                    } else if (count >=9) {
////                                        count = screwNum52List.get(count + 1);
////                                    }
//
//                                    LambdaQueryWrapper<screwType> queryWrapper = new LambdaQueryWrapper<>();
//                                    queryWrapper.eq(screwType::getScrewId, screwTypeId2);
//                                    queryWrapper.eq(screwType::getWeldingGunId, 52);
//                                    screwType screwType = screwTypeMapper.selectOne(queryWrapper);
////                                    screwType screwType = screwTypeMapper.selectById(screwTypeId);
//
//                                    map.put("screwType",screwType);
//
//                                    map.put("ScrewId", ScrewId2);//null
//                                    ScrewId2 ++;
//                                    map.put("workPositionId", MessageConstant.workingPosition1);
//                                    map.put("torque", 23456);
//                                    map.put("unit", MessageConstant.torqueUnit);
//                                    String json = JSON.toJSONString(map);
//                                    log.info("json推消息重置前端红点1:"+json);
//                                    webSocketServer.sendToAllClient(json);//推消息
//                                    try {
//                                        Thread.sleep(2000);//150
//                                    } catch (InterruptedException e) {
//                                        throw new RuntimeException(e);
//                                    }
//                                }
////-------------------------------------------------------
//                                LambdaQueryWrapper<Car> carWrapper = new LambdaQueryWrapper<>();
//                                carWrapper.eq(Car::getCarId, car1Num.trim());
//                                carWrapper.eq(Car::getCarType, car1Type.trim());
//                                carWrapper.eq(Car::getRepeatNum, repeat1.trim());
////                              carMapper.selectCount(carWrapper) == 0 &&
//
////                                Car car0 = new Car();
////                                if(cars.size() >= 1) {
////                                    car0 = cars.get(0);
////                                }
////                                Car car1 = new Car();
////                                if(cars.size() >= 2) {
////                                    car1 = cars.get(1);
////                                }
//
////                                log.info("当前车1是"+car1Num.trim()+"-"+car1Type.trim()+"-"+repeat1.trim());
//
////                                if(((!car0.getRepeatNum().equals(car1Num.trim())) ||
////                                        !car0.getCarType().equals(car1Type.trim()) ||
////                                        !car0.getRepeatNum().equals(repeat1.trim()))
////                                        &&
////                                        (!car1Num.trim().isEmpty() ||
////                                                !car1Type.trim().isEmpty() ||
////                                                !repeat1.trim().isEmpty())) {
//                                // -----------------和最新的一个判断
////                                if((!car0.getRepeatNum().equals(repeat1.trim())) &&
////                                        (!car1.getRepeatNum().equals(repeat1.trim()))
////                                        &&
////                                        (!car1Num.trim().isEmpty() ||
////                                        !car1Type.trim().isEmpty() ||
////                                        !repeat1.trim().isEmpty())) {
//                                //  ------------------- 和最新的两个判断
//                                if((carMapper.selectCount(carWrapper) == 0 &&
//                                        (!car1Num.trim().isEmpty() ||
//                                        !car1Type.trim().isEmpty() ||
//                                        !repeat1.trim().isEmpty()))) {
//                                    // 如果数据库中没有该条数据，则插入该条数据
//                                    log.info("数据库中没有" + car1Num + "这辆车");
//                                    Car car = new Car();
//                                    car.setCarId(car1Num.trim());
//                                    car.setCarType(car1Type.trim());
//                                    car.setRepeatNum(repeat1.trim());
//                                    //车身拼接过前缀之后才能存进数据库
//                                    Object carNumPrefix = CacheUtil.getFromCache("carNumPrefix");
//                                    String carNumPrefixString = "";
//                                    if (carNumPrefix != null) {
//                                        carNumPrefixString = String.valueOf(carNumPrefix);
//                                    }
////                                    Object yymmdd = CacheUtil.getFromCache("yymmdd");
////                                    String yymmddString = "";
////                                    if (yymmdd != null) {
////                                        yymmddString = (String) yymmdd;
////                                    }
//
////                                    log.info("carNumPrefixString是"+carNumPrefixString);
//                                    if (car1Num.trim().length() >= 2 && !car1Type.equals("未知车型") && !car1Num.contains("null")) {
////                                        log.info("车身号最后两位是" + car1Num.trim()
//                                                //.substring(car1Num.trim().length() - 2));
//
//                                        //不管插入的车辆了
//                                        //(car1Num.trim().contains(carNumPrefixString) || car1Num.trim().contains(yymmddString))
//                                        if (car1Num.trim().contains(carNumPrefixString) &&
//                                                //确报拼接过连番号
//                                                car1Num.trim()
//                                                        .substring(car1Num.trim().length() - 2)
//                                                        .contains(repeat1.trim())) {
//                                            log.info(car1Num.trim() + "保存车辆" + car);
//                                            car.setWorkingPositionId(MessageConstant.workingPosition1);
//                                            carService.save(car);
//                                        }
//                                    }
//                                }
//
//                            }
//
//                            if(!repeat1Cache.equals(repeat1) ||
//                                    !repeat2Cache.equals(repeat2)){
//                                //无论之前是否是红灯，清理红灯缓存并统统绿灯
//                                List<Long> redLight = new ArrayList<>();
//                                CacheUtil.putInCache("redLight", redLight);
////                                log.info("绿灯亮?");
//                                jSerialCommIOService.greenUp();
//                            }
//
//                            if (car2NumCache.equals(car2Num) &&
//                                    car2TypeCache.equals(car2Type) &&
//                                    repeat2Cache.equals(repeat2)) {
//                                // 与上一次监控到的值相同，取消当前任务并立即跳到下一个周期
//                                log.info("与上一次监控到的car2值相同，等待跳到下一个周期.");
//                            }else {//防止plc断开的时候的情况也清理前端的告警点
//                                //else if(!car2Num.isEmpty() && !car2Type.isEmpty() && !repeat2.isEmpty())
//                                // 与上一次监控到的值不同，继续监控下一次
//                                log.info("与上一次监控到的car2值不同，缓存以及保存当前车的信息，让心跳端读取");
//                                //清理工位二的扭力标准缓存
////                                CacheUtil.removeFromCache("standard1");
//                                //CacheUtil.removeFromCache("standard1max");
//                                CacheUtil.removeFromCache("standard2");
//                                //CacheUtil.removeFromCache("standard2max");
//                                //更新缓存
//                                CacheUtil.putInCache("carNum2", car2Num.trim());
//                                CacheUtil.putInCache("carType2", car2Type.trim());
//                                CacheUtil.putInCache("repeat2", repeat2.trim());
//
//                                //无论之前是否是红灯，清理红灯缓存并统统绿灯
////                                List<Long> redLight = new ArrayList<>();
////                                CacheUtil.putInCache("redLight", redLight);
//////                                CacheUtil.removeFromCache("redLight");
////                                jSerialCommIOService.greenUp();
//                                //清理前端的螺丝缓存
//                                for (int count = 17; count <= 20; count++) {
//                                    CacheUtil.removeFromCache("screw"+ count);
////                                    CacheUtil.putInCache("screw"+ count, null);
////                                    CacheUtil.putInCache("screw"+ count, 0.00); // 也可以用 null
//                                }
////------------------------------------------------------
////                                Object alarmsTime0 =  CacheUtil.getFromCache("alarmsTime");
////                                int alarmsTime = 0;
////                                if(alarmsTime0!=null){
////                                    alarmsTime = (int) alarmsTime0;
////                                }
////
////                                long ScrewId1 = 1;
////                                int screwTypeId1;//, 13, 14, 15, 16, 9, 10, 11, 12
////                                List<Integer> screwNum53List = Arrays.asList(1, 2);
////                                for (int count = 0; count <= 1; count++) {
////                                    Map map = new HashMap();
////                                    //清理前端的所有信息缓存红点等等
//////                                    map.put("alert", -1);
//////                                      map.put("alert", 2);//全红
//////                                    map.put("alert", 0);//全红
////                                    map.put("alert", 1);//全绿
////                                    Object object = CacheUtil.getFromCache("redLight");
//////                                    List<Long> redLight0;
////                                    if (object == null){
////                                        List<Long> redLight0 = new ArrayList<>();
////                                        redLight0.add(ScrewId1);
////                                        log.info("没有红灯缓存，新建"+redLight0);
////                                        CacheUtil.putInCache("redLight",redLight0);
////                                    }else {//如果有就加多一个
////                                        List<Long> redLight0 = (List<Long>) object;//TODO 拧紧枪测试。。。
////                                        redLight0.add(ScrewId1);
////                                        log.info("有红灯缓存，添加"+redLight0);
////                                        CacheUtil.putInCache("redLight",redLight0);
////                                    }
////
////                                    map.put("alarmsTime", alarmsTime);
////
//////                                    if(count <= 8) {
////                                    screwTypeId1 = screwNum53List.get(count);
//////                                    } else if (count >=9) {
//////                                        count = screwNum52List.get(count + 1);
//////                                    }
////
////                                    LambdaQueryWrapper<screwType> queryWrapper = new LambdaQueryWrapper<>();
////                                    queryWrapper.eq(screwType::getScrewId, screwTypeId1);
////                                    queryWrapper.eq(screwType::getWeldingGunId, 53);
////                                    screwType screwType = screwTypeMapper.selectOne(queryWrapper);
//////                                    screwType screwType = screwTypeMapper.selectById(screwTypeId);
////
////                                    map.put("screwType",screwType);
////
////                                    map.put("ScrewId", ScrewId1);//null
////                                    ScrewId1 ++;
////                                    map.put("workPositionId", MessageConstant.workingPosition2);
////                                    map.put("torque", 23456);
////                                    map.put("unit", MessageConstant.torqueUnit);
////                                    String json = JSON.toJSONString(map);
////                                    log.info("json推消息重置前端红点2:"+json);
////                                    webSocketServer.sendToAllClient(json);//推消息
////                                    try {
////                                        Thread.sleep(2000);//150
////                                    } catch (InterruptedException e) {
////                                        throw new RuntimeException(e);
////                                    }
////                                }
////
////                                long ScrewId2 = 1;
////                                int screwTypeId2;//, 13, 14, 15, 16, 9, 10, 11, 12
////                                List<Integer> screwNum54List = Arrays.asList(1, 2);
////                                for (int count = 0; count <= 1; count++) {
////                                    Map map = new HashMap();
////                                    //清理前端的所有信息缓存红点等等
//////                                    map.put("alert", -1);
//////                                      map.put("alert", 2);//全红
//////                                    map.put("alert", 0);//全红
////                                    map.put("alert", 1);//全绿
////                                    Object object = CacheUtil.getFromCache("redLight");
//////                                    List<Long> redLight0;
////                                    if (object == null){
////                                        List<Long> redLight0 = new ArrayList<>();
////                                        redLight0.add(ScrewId1);
////                                        log.info("没有红灯缓存，新建"+redLight0);
////                                        CacheUtil.putInCache("redLight",redLight0);
////                                    }else {//如果有就加多一个
////                                        List<Long> redLight0 = (List<Long>) object;//TODO 拧紧枪测试。。。
////                                        redLight0.add(ScrewId1);
////                                        log.info("有红灯缓存，添加"+redLight0);
////                                        CacheUtil.putInCache("redLight",redLight0);
////                                    }
////
////                                    map.put("alarmsTime", alarmsTime);
////
//////                                    if(count <= 8) {
////                                    screwTypeId2 = screwNum54List.get(count);
//////                                    } else if (count >=9) {
//////                                        count = screwNum52List.get(count + 1);
//////                                    }
////
////                                    LambdaQueryWrapper<screwType> queryWrapper = new LambdaQueryWrapper<>();
////                                    queryWrapper.eq(screwType::getScrewId, screwTypeId2);
////                                    queryWrapper.eq(screwType::getWeldingGunId, 54);
////                                    screwType screwType = screwTypeMapper.selectOne(queryWrapper);
//////                                    screwType screwType = screwTypeMapper.selectById(screwTypeId);
////
////                                    map.put("screwType",screwType);
////
////                                    map.put("ScrewId", ScrewId2);//null
////                                    ScrewId2 ++;
////                                    map.put("workPositionId", MessageConstant.workingPosition2);
////                                    map.put("torque", 23456);
////                                    map.put("unit", MessageConstant.torqueUnit);
////                                    String json = JSON.toJSONString(map);
////                                    log.info("json推消息重置前端红点2:"+json);
////                                    webSocketServer.sendToAllClient(json);//推消息
////                                    try {
////                                        Thread.sleep(2000);//150
////                                    } catch (InterruptedException e) {
////                                        throw new RuntimeException(e);
////                                    }
////                                }
////--------------------------------------
//                                //测试
////                                for (int count = 17; count <= 20; count++) {
////                                    Map map = new HashMap();
////                                    //清理前端的所有信息缓存红点等等
////                                    map.put("alert", -1);
////
////                                    map.put("alarmsTime", alarmsTime);
////                                    screwType screwType = screwTypeMapper.selectById(count);
////                                    map.put("screwType",screwType);
//////                                    ScrewId ++;ScrewId
////                                    map.put("ScrewId", null);//
////                                    map.put("workPositionId", MessageConstant.workingPosition2);
////                                    map.put("torque", 0);
////                                    map.put("unit", MessageConstant.torqueUnit);
////                                    String json = JSON.toJSONString(map);
////                                    log.info("json推消息重置前端红点2:"+json);
////                                    webSocketServer.sendToAllClient(json);//推消息
////                                    try {
////                                        Thread.sleep(0);
////                                    } catch (InterruptedException e) {
////                                        throw new RuntimeException(e);
////                                    }
////                                }
//                                //----------------------------------------------------
//
////                                log.info("当前车2是"+car2Num.trim()+"-"+car2Type.trim()+"-"+repeat2.trim());
//
//                                LambdaQueryWrapper<Car> carWrapper = new LambdaQueryWrapper<>();
//                                carWrapper.eq(Car::getCarId, car2Num.trim());
//                                carWrapper.eq(Car::getCarType, car2Type.trim());
//                                carWrapper.eq(Car::getRepeatNum, repeat2.trim());
//                                if((carMapper.selectCount(carWrapper) == 0 &&
//                                        (!car2Num.trim().isEmpty() ||
//                                                !car2Type.trim().isEmpty() ||
//                                                !repeat2.trim().isEmpty()))) {
//                                    // 如果数据库中没有该条数据，则插入该条数据
//                                    log.info("数据库中没有" + car2Num + "这辆车");
//                                    Car car = new Car();
//                                    car.setCarId(car2Num.trim());
//                                    car.setCarType(car2Type.trim());
//                                    car.setRepeatNum(repeat2.trim());
//                                    //车身拼接过前缀之后才能存进数据库
//                                    Object carNumPrefix = CacheUtil.getFromCache("carNumPrefix2");
//                                    String carNumPrefixString = "";
//                                    if (carNumPrefix != null) {
//                                        carNumPrefixString = String.valueOf(carNumPrefix);
//                                    }
////                                    Object yymmdd = CacheUtil.getFromCache("yymmdd");
////                                    String yymmddString = "";
////                                    if (yymmdd != null) {
////                                        yymmddString = (String) yymmdd;
////                                    }
//
////                                    log.info("carNumPrefixString2是"+carNumPrefixString);
//                                    if (car2Num.trim().length() >= 2 && !car2Type.equals("未知车型") && !car2Num.contains("null")) {
////                                        log.info("车身号最后两位是" + car2Num.trim()
//                                                //.substring(car2Num.trim().length() - 2));
//
//                                        //不管插入的车辆了
//                                        //(car2Num.trim().contains(carNumPrefixString) || car2Num.trim().contains(yymmddString)
//                                        if (car2Num.trim().contains(carNumPrefixString) &&
//                                                //确报拼接过连番号
//                                                car2Num.trim()
//                                                        .substring(car2Num.trim().length() - 2)
//                                                        .contains(repeat2.trim())) {
//                                            log.info(car2Num.trim() + "保存车辆" + car);
//                                            car.setWorkingPositionId(MessageConstant.workingPosition2);
//                                            carService.save(car);
//                                        }
//                                    }
//                                }
//
//                            }
//                        }
//                    }, 0, frequencyProperties.getCacheFrequency()); // 每 1000 ms 运行一次MessageConstant.cacheFrequency
//                }).get();
//        // 持续订阅
//        //让线程“永久等待”而不退出
//        Thread.sleep(Long.MAX_VALUE);
//        return 0;
//    }
//
//
//    //@Suspendable
//    private void retryAndNoData(String car1Num, String car1Type, String repeat1,
//                                String car2Num, String car2Type, String repeat2) {
//        if(car1Num.isEmpty() &&
//                car1Type.isEmpty() &&
//                repeat1.isEmpty() &&
//                car2Num.isEmpty() &&
//                car2Type.isEmpty() &&
//                repeat2.isEmpty()){
////            log.info("PLC断开重连");
////            log.info("无数据");
//            Map<String, String> map0 = new HashMap<>();
//            map0.put("car1Num", "无数据");
//            map0.put("car1Type", "无数据");
//            map0.put("repeat1", "无数据");
//            map0.put("standard1min",  "");
//            map0.put("standard1max",  "");
//            map0.put("car2Num", "无数据");
//            map0.put("car2Type", "无数据");
//            map0.put("repeat2", "无数据");
//            map0.put("standard2min",  "");
//            map0.put("standard2max",  "");
//            //把map转为json
//            String json0 = JSON.toJSONString(map0);
//            log.info("plc无数据的json是"+json0);
//            webSocketServer.sendToAllClient(json0);//推消息
//            CacheUtil.removeFromCache("standard1");
//            //CacheUtil.removeFromCache("standard1max");
//            CacheUtil.removeFromCache("standard2");
//            //CacheUtil.removeFromCache("standard2max");
////             try {
////                 waitTime = Math.min(frequencyProperties.getMonitorNodeFrequency()
////                         + 500, MAX_WAIT_TIME);
////                 Thread.sleep(waitTime);
////                } catch (Exception e) {
////                throw new RuntimeException(e);
////            }
//
//            try {
//                Thread.sleep(frequencyProperties.getMonitorNodeFrequency());
//            } catch (Exception e) {
//                log.info(e.getMessage());
//                e.printStackTrace();
////                throw new RuntimeException(e);
//            }
////            Map map = new HashMap();
////            map.put("message", "····PLC已无数据，请检查设备···");
////            String json = JSON.toJSONString(map);
////            webSocketServer.sendToAllClient(json);//推消息
////            retrySubscribe();
//        }else if(car1Num.isEmpty() &&
//                car1Type.isEmpty() &&
//                repeat1.isEmpty() &&
//                !car2Num.isEmpty() &&
//                !car2Type.isEmpty() &&
//                !repeat2.isEmpty()){
//            log.info("只是工位一没有数据，PLC不用重连");
//            Map<String, String> map0 = new HashMap<>();
//            map0.put("car1Num", "无数据");
//            map0.put("car1Type",  "无数据");
//            map0.put("repeat1",  "无数据");
//            map0.put("standard1min",  "");
//            map0.put("standard1max",  "");
//            CacheUtil.removeFromCache("standard1");
//            //CacheUtil.removeFromCache("standard1max");
////            CacheUtil.putInCache("standard1",null);
//            map0.put("car2Num", car2Num);
//            map0.put("car2Type", car2Type);
//            map0.put("repeat2", repeat2);
//            LambdaQueryWrapper<TorqueStandards> torqueStandardsWrapper = new LambdaQueryWrapper<>();
//            torqueStandardsWrapper.eq(TorqueStandards::getCarType, car2Type.trim());
//            torqueStandardsWrapper.eq(TorqueStandards::getWorkingPositionId, MessageConstant.workingPosition2);
//            int count = torqueStandardsMapper.selectCount(torqueStandardsWrapper);
//            if(count == 0){
//                map0.put("standard2min", "");
//                map0.put("standard2max", "");
//                CacheUtil.removeFromCache("standard2");
//                //CacheUtil.removeFromCache("standard2max");
//            } else if(count == 1) {
//                TorqueStandards torqueStandards = torqueStandardsMapper.selectOne(torqueStandardsWrapper);
//                CacheUtil.putInCache("standard2",torqueStandards);
//                //CacheUtil.putInCache("standard2max",torqueStandards.getMaximumTorque());
//                map0.put("standard2min", torqueStandards.getMinimumTorque().toString());
//                map0.put("standard2max", torqueStandards.getMaximumTorque().toString());
////                String json = JSON.toJSONString(torqueStandards);
////                map0.put("standard2", json);
//            }else {
//                log.info("数据异常-----");
//                map0.put("standard2min", "数据异常");
//                map0.put("standard2max", "数据异常");
//                CacheUtil.removeFromCache("standard2");
//                //CacheUtil.removeFromCache("standard2max");
//            }
//
//            //把map转为json
//            String json0 = JSON.toJSONString(map0);
////            log.info("车的json是"+json0);
//            webSocketServer.sendToAllClient(json0);//推消息
//            try {
////                Strand.sleep(frequencyProperties.getMonitorNodeFrequency());
//                Thread.sleep(frequencyProperties.getMonitorNodeFrequency());
////                                    retrySubscribe();
//            } catch (Exception e) {
//                log.info(e.getMessage());
//                e.printStackTrace();
////                throw new RuntimeException(e);
//            }
//        } else if(!car1Num.isEmpty() &&
//                !car1Type.isEmpty() &&
//                !repeat1.isEmpty() &&
//                car2Num.isEmpty() &&
//                car2Type.isEmpty() &&
//                repeat2.isEmpty()) {
//            log.info("只是工位二没有数据，PLC不用重连");
//            Map<String, String> map0 = new HashMap<>();
//            map0.put("car1Num", car1Num);
//            map0.put("car1Type", car1Type);
//            map0.put("repeat1", repeat1);
//            LambdaQueryWrapper<TorqueStandards> torqueStandardsWrapper = new LambdaQueryWrapper<>();
//            torqueStandardsWrapper.eq(TorqueStandards::getCarType, car1Type.trim());
//            torqueStandardsWrapper.eq(TorqueStandards::getWorkingPositionId, MessageConstant.workingPosition1);
//            int count = torqueStandardsMapper.selectCount(torqueStandardsWrapper);
//            if(count == 0){
//                map0.put("standard1min", "");
//                map0.put("standard1max", "");
//                CacheUtil.removeFromCache("standard1");
//                //CacheUtil.removeFromCache("standard1max");
//            } else if(count == 1) {
//                TorqueStandards torqueStandards = torqueStandardsMapper.selectOne(torqueStandardsWrapper);
//                CacheUtil.putInCache("standard1",torqueStandards);
//                //CacheUtil.putInCache("standard1max",torqueStandards.getMaximumTorque());
//                map0.put("standard1min", String.valueOf(torqueStandards.getMinimumTorque()));
//                map0.put("standard1max", String.valueOf(torqueStandards.getMaximumTorque()));
////                String json = JSON.toJSONString(torqueStandards);
////                map0.put("standard1", json);
//            }else {
//                log.info("数据异常-----");
//                map0.put("standard1min", "数据异常");
//                map0.put("standard1max", "数据异常");
//                CacheUtil.removeFromCache("standard1");
//                //CacheUtil.removeFromCache("standard1max");
//            }
//
//            map0.put("car2Num", "无数据");
//            map0.put("car2Type",  "无数据");
//            map0.put("repeat2",  "无数据");
//            map0.put("standard2min",  "");
//            map0.put("standard2max",  "");
//            CacheUtil.removeFromCache("standard2");
//            //CacheUtil.removeFromCache("standard2max");
////            CacheUtil.putInCache("standard2",null);
//            //把map转为json
//            String json0 = JSON.toJSONString(map0);
////            log.info("车的json是"+json0);
//            webSocketServer.sendToAllClient(json0);//推消息
//            try {
////                Strand.sleep(frequencyProperties.getMonitorNodeFrequency());
//                Thread.sleep(frequencyProperties.getMonitorNodeFrequency());
////                                    retrySubscribe();
//            } catch (Exception e) {
//                log.info(e.getMessage());
//                e.printStackTrace();
////                throw new RuntimeException(e);
//            }
//        }
//    }
//
//    //优化后：
//
//
//
//    //------------------------------------------
//    //优化前：
//    // 模拟发送数据到前端的函数
//    //@Suspendable
//    private Map<String, String> sendToFrontEnd(Map<NodeId, Object> monitoredValues){// throws Exception   throws InterruptedException
//        log.info("监控到的节点数据: " + monitoredValues);
//        if(monitoredValues.isEmpty()){
//            log.info("监控到空的节点数据");
//            Map<String, String> map0 = new HashMap<>();
////            jSerialCommIOService.yellowUp();
//
//            map0.put("car1Num", "OPC重连中");
//            map0.put("car1Type", "OPC重连中");
//            map0.put("repeat1", "OPC重连中");
//            map0.put("standard1min", "");
//            map0.put("standard1max", "");
//            CacheUtil.removeFromCache("standard1");
//            //CacheUtil.removeFromCache("standard1max");
//            map0.put("car2Num", "OPC重连中");
//            map0.put("car2Type", "OPC重连中");
//            map0.put("repeat2", "OPC重连中");
//            map0.put("standard2min", "");
//            map0.put("standard2max", "");
//            CacheUtil.removeFromCache("standard2");
//            //CacheUtil.removeFromCache("standard2max");
//            //把map转为json
//            String json0 = JSON.toJSONString(map0);
////            webSocketServer.sendToAllClient(json0);//推消息
//            return null;
//        }
//
//        // 检查 monitoredValues 是否为 null
//        String monitoredValuesStr = null; // 初始化为 null
////        if (monitoredValues != null) {
//            monitoredValuesStr = monitoredValues.toString();
//
//        String carTypeSuffix1 = carNodeProperties.getCarTypeSuffix1() != null ? carNodeProperties.getCarTypeSuffix1() : "";
//        String carTypeSuffix2 = carNodeProperties.getCarTypeSuffix2() != null ? carNodeProperties.getCarTypeSuffix2() : "";
//        String repeatSuffix1 = carNodeProperties.getRepeatSuffix1() != null ? carNodeProperties.getRepeatSuffix1() : "";
//        String repeatSuffix2 = carNodeProperties.getRepeatSuffix2() != null ? carNodeProperties.getRepeatSuffix2() : "";
////        log.info("because s is null1");
//        boolean containsNull1 = monitoredValues.toString().contains(carTypeSuffix1 + "}=null");
//        boolean containsNull2 = monitoredValues.toString().contains(carTypeSuffix2 + "}=null");
//        boolean containsNull3 = monitoredValues.toString().contains(repeatSuffix1 + "}=null");
//        boolean containsNull4 = monitoredValues.toString().contains(repeatSuffix2 + "}=null");
//
////        log.info("carTypeSuffix12和repeatSuffix12分别是"+carTypeSuffix1+" "+carTypeSuffix2+" "
////                +repeatSuffix1+" "+repeatSuffix2);
//
//        if ((containsNull1 && containsNull2 && containsNull3 && containsNull4)
//                || (!monitoredValuesStr.contains(carTypeSuffix1) &&
//                !monitoredValuesStr.contains(carTypeSuffix2) &&
//                !monitoredValuesStr.contains(repeatSuffix1) &&
//                !monitoredValuesStr.contains(repeatSuffix2))) {
//            log.info("plc真断了？？？------------------");
//            Map<String, String> map0 = new HashMap<>();
//            map0.put("car1Num", "PLC已断开");
//            map0.put("car1Type", "PLC已断开");
//            map0.put("repeat1", "PLC已断开");
//            map0.put("standard1min", "");
//            map0.put("standard1max", "");
//            CacheUtil.removeFromCache("standard1");
//            //CacheUtil.removeFromCache("standard1max");
//            map0.put("car2Num", "plc已断开");
//            map0.put("car2Type", "plc已断开");
//            map0.put("repeat2", "plc已断开");
//            map0.put("standard2min", "");
//            map0.put("standard2max", "");
//            CacheUtil.removeFromCache("standard2");
//            //CacheUtil.removeFromCache("standard2max");
//            //把map转为json
//            String json0 = JSON.toJSONString(map0);
////            log.info("plc已断开的json是"+json0);
//            webSocketServer.sendToAllClient(json0);//推消息
//            //蜂鸣器响5秒
//            jSerialCommIOService.buzzerControl();
//            try {
//                // 挂起当前协程一段时间后重试
////                Strand.sleep(frequencyProperties.getMonitorNodeFrequency());
//                Thread.sleep(frequencyProperties.getMonitorNodeFrequency());
//            } catch (Exception e) {
////                log.info("睡眠问题？？？");
//                log.info(e.getMessage());
//                e.printStackTrace();
////                throw new RuntimeException(e);
//            }
//            return null;
//        }
//
//        // 存储 carNum 和 carType 的列表
//        List<String> carNumList = new ArrayList<>();
//        List<String> carTypeList = new ArrayList<>();
//        List<String> repeatList = new ArrayList<>();
//
//// 遍历每一个 monitoredValues 的 entry
//        for (Map.Entry<NodeId, Object> entry : monitoredValues.entrySet()) {
//            String idString = entry.toString();
////            log.info("idString是"+idString);
//            // 分类到相应的列表中MessageConstant.nodeNull+MessageConstant.carNum
//            if (idString.startsWith(carNodeProperties.getNodeNull() + carNodeProperties.getCarNum())) {
//                carNumList.add(idString); // 将 carNum ID 添加到列表MessageConstant.nodeNull+MessageConstant.carType
//            } else if (idString.startsWith(carNodeProperties.getNodeNull() + carNodeProperties.getCarType())) {
//                carTypeList.add(idString); // 将 carType ID 添加到列表MessageConstant.nodeNull+MessageConstant.repeat
//            } else if (idString.startsWith(carNodeProperties.getNodeNull() + carNodeProperties.getRepeat())) {
//                repeatList.add(idString); // 将 repeat ID 添加到列表
//            }else {
//                log.info("idString是"+idString);
//            }
//        }
//        Map<String, String> carTypeMap = process(carTypeList);
//        List<String> carTypeMap1 = Collections.singletonList(carTypeMap.get("asciiBuilder1"));
//        List<String> carTypeMap2 = Collections.singletonList(carTypeMap.get("asciiBuilder2"));
//        Map<String, String> repeatMap = process(repeatList);
//        List<String> repeatMap1 = Collections.singletonList(repeatMap.get("asciiBuilder1"));
//        List<String> repeatMap2 = Collections.singletonList(repeatMap.get("asciiBuilder2"));
//
////        String car1Num = carNumMap1.toString().replaceAll("^[\\[\\s]+|[\\]\\s]+$", "");
////        String car2Num = carNumMap2.toString().replaceAll("^[\\[\\s]+|[\\]\\s]+$", "");
//        String car1Num = null;
//        String car2Num = null;
//        String car1Type = carTypeMap1.toString().replaceAll("^[\\[\\s]+|[\\]\\s]+$", "");
//        String car2Type = carTypeMap2.toString().replaceAll("^[\\[\\s]+|[\\]\\s]+$", "");
//        String repeat1 = repeatMap1.toString().replaceAll("^[\\[\\s]+|[\\]\\s]+$", "");
//        String repeat2 = repeatMap2.toString().replaceAll("^[\\[\\s]+|[\\]\\s]+$", "");
//
//        if(repeat1.length() == 1){
//            repeat1 = "0"+repeat1;
//        }
//
//        if(repeat2.length() == 1){
//            repeat2 = "0"+repeat2;
//        }
//
//        if(car1Type.equals(carTypeProperties.getCamryOriginal1())){
//            car1Type = carTypeProperties.getCamry();
//        }else if (car1Type.equals(carTypeProperties.getLevinOriginal1())) {
//            car1Type = carTypeProperties.getLevin();
//        }else {
//            car1Type = "未知车型";
//        }
//
//        if(car2Type.equals(carTypeProperties.getCamryOriginal2())){
//            car2Type = carTypeProperties.getCamry();
//        }else if(car2Type.equals(carTypeProperties.getLevinOriginal2())){
//            car2Type = carTypeProperties.getLevin();
//        }else {
//            car2Type = "未知车型";
//        }
//
//        log.info("车1车型是"+car1Type+"连番"+repeat1);
//        log.info("车2车型是"+car2Type+"连番"+repeat2);
//
//        //应该在这里处理
//        LocalDate today = LocalDate.now();
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//        //今天
//        String todayStr = today.format(formatter);
//        //昨天
//        String yesterdayStr = today.minusDays(1).format(formatter);
////        String yymmdd = formatToYYMMDD(todayStr);
////        String yymmdd0 = formatToYYMMDD(yesterdayStr);
////        CacheUtil.putInCache("yymmdd",yymmdd);
////        CacheUtil.putInCache("yymmdd0",yymmdd0);
////        log.info("今天是"+yymmdd);
//
//        LambdaQueryWrapper<CarNumPrefix> queryWrapper = new LambdaQueryWrapper<>();
//        LambdaQueryWrapper<CarNumPrefix> queryWrapperYes = new LambdaQueryWrapper<>();
//        LambdaQueryWrapper<CarNumPrefix> queryWrapper2 = new LambdaQueryWrapper<>();
//        LambdaQueryWrapper<CarNumPrefix> queryWrapperYes2 = new LambdaQueryWrapper<>();
//
//        queryWrapper.like(CarNumPrefix::getCreateTime, todayStr);
//        queryWrapper.eq(CarNumPrefix::getWorkingPositionId, MessageConstant.workingPosition1);
//        queryWrapper2.like(CarNumPrefix::getCreateTime, todayStr);
//        queryWrapper2.eq(CarNumPrefix::getWorkingPositionId, MessageConstant.workingPosition2);
//
//        queryWrapperYes.like(CarNumPrefix::getCreateTime, yesterdayStr);
//        queryWrapperYes.eq(CarNumPrefix::getWorkingPositionId, MessageConstant.workingPosition1);
//        queryWrapperYes2.like(CarNumPrefix::getCreateTime, yesterdayStr);
//        queryWrapperYes2.eq(CarNumPrefix::getWorkingPositionId, MessageConstant.workingPosition2);
//        int carNumPrefixCount = carNumPrefixMapper.selectCount(queryWrapper);
////        log.info("carNumPrefixCount是"+carNumPrefixCount);
////        int carNumPrefixCountYes = carNumPrefixMapper.selectCount(queryWrapperYes);
//        int carNumPrefixCount2 = carNumPrefixMapper.selectCount(queryWrapper2);
////        int carNumPrefixCountYes2 = carNumPrefixMapper.selectCount(queryWrapperYes2);
////        log.info("carNumPrefixCount2是"+carNumPrefixCount2);
//
//        CarNumPrefix carNumPrefix = new CarNumPrefix();
//        if(carNumPrefixCount == 1){
//            carNumPrefix = carNumPrefixMapper.selectOne(queryWrapper);
//            //其它地方需要调用
//            if (carNumPrefix != null && carNumPrefix.getCarNum() != null) {
//                CacheUtil.putInCache("carNumPrefix", carNumPrefix.getCarNum().trim());
//            }
//        }else if(carNumPrefixCount > 1){
//            log.info("数据库存在多个车身号前缀");
//            Map map = new HashMap();
//            try {
//                Thread.sleep(12000);
//            } catch (InterruptedException e) {
//                log.info(e.getMessage());
//                e.printStackTrace();
//            }
//            map.put("message", "..存在多个车身号前缀，请联系管理员..");
//            String json = JSON.toJSONString(map);
//            webSocketServer.sendToAllClient(json);
//        }else {
//            carNumPrefix = null;
//        }
//
//        CarNumPrefix carNumPrefix2 = new CarNumPrefix();
//        if(carNumPrefixCount2 == 1){
//            carNumPrefix2 = carNumPrefixMapper.selectOne(queryWrapper2);
//            log.info("carNumPrefix2是"+carNumPrefix2);
//            //其它地方需要调用
//            if (carNumPrefix2 != null && carNumPrefix2.getCarNum() != null) {
//                CacheUtil.putInCache("carNumPrefix2", carNumPrefix2.getCarNum().trim());
//            }
//        }else if(carNumPrefixCount2 > 1){
//            log.info("数据库存在多个车身号前缀");
//            Map map = new HashMap();
//            try {
//                Thread.sleep(12000);
//            } catch (InterruptedException e) {
//                log.info(e.getMessage());
//                e.printStackTrace();
//            }
//            map.put("message", "..存在多个车身号前缀，请联系管理员..");
//            String json = JSON.toJSONString(map);
//            webSocketServer.sendToAllClient(json);
//        }else {
//            carNumPrefix2 = null;
//        }
//
//                log.info("用数据库的车身号前缀");
//                //用数据库里的前缀和连番进行拼接，构建车身号
////                try {
//                    //TODO 假如i.get("repeat1").trim()是01，repeat1会变成1
//                    int repeat1Int = -1;
//                    int repeat2Int = -1;
//                    if (!repeat1.trim().isEmpty() && repeat1.trim().matches("-?\\d+")) {
//                        log.info("repeat1是数字" + repeat1);
//                        repeat1Int = Integer.parseInt(repeat1.trim());
//                    } else {
//                        log.info("repeat1不是数字");
//                        try {
//                            Thread.sleep(12000);
//                        } catch (InterruptedException e) {
//                            log.info(e.getMessage());
//                            e.printStackTrace();
//                        }
//                        Map map = new HashMap();
//                        map.put("message", "..门铰链工位的连番必须是数字..");
//                        String json = JSON.toJSONString(map);
//                        webSocketServer.sendToAllClient(json);
//                    }
//
//                    if (!repeat2.trim().isEmpty() && repeat2.trim().matches("-?\\d+")) {
////                        log.info("repeat2是数字" + repeat2);
//                        repeat2Int = Integer.parseInt(repeat2.trim());
//                    } else {
//                        log.info("repeat2不是数字");
//                        try {
//                            Thread.sleep(12000);
//                        } catch (InterruptedException e) {
//                            log.info(e.getMessage());
//                            e.printStackTrace();
//                        }
//                        Map map = new HashMap();
//                        map.put("message", "..发动机盖工位的连番必须是数字..");
//                        String json = JSON.toJSONString(map);
//                        webSocketServer.sendToAllClient(json);
//                    }
//
//
//                    LambdaQueryWrapper<Car> queryCarWrapper = new LambdaQueryWrapper<>();
//                    LambdaQueryWrapper<Car> queryCarWrapper2 = new LambdaQueryWrapper<>();
//                    // 根据创建时间排序
//                    queryCarWrapper.orderByDesc(Car::getCreateTime);
//                    queryCarWrapper2.orderByDesc(Car::getCreateTime);
//                    // 使用 last 方法添加 LIMIT 3
//                    queryCarWrapper.last("LIMIT 4");
//                    queryCarWrapper2.last("LIMIT 4");
////                    queryCarWrapper.last("LIMIT 3");
////                    queryCarWrapper2.last("LIMIT 3");
////                    queryCarWrapper.eq(Car::getWorkingPositionId, MessageConstant.workingPosition1);
////                    queryCarWrapper2.eq(Car::getWorkingPositionId, MessageConstant.workingPosition2);
//                    List<Car> carList = carMapper.selectList(queryCarWrapper);
//                    List<Car> carList2 = carMapper.selectList(queryCarWrapper2);
//                    log.info("最新四条");
//                    Car car1 = new Car();
//                    Car car12 = new Car();
//                    if (!carList.isEmpty()) {
//                        car1 = carList.get(0);
//                        log.info("car1是" + car1);
//                    }
//                    if (!carList2.isEmpty()) {
//                        car12 = carList2.get(0);
//                        log.info("car12是" + car12);
//                    }
//
//                    Car car2 = new Car();
//                    Car car22 = new Car();
//                    if (carList.size() >= 2) {
//                        car2 = carList.get(1);
//                        log.info("car2是" + car2);
//                    }
//                    if (carList2.size() >= 2) {
//                        car22 = carList2.get(1);
//                        log.info("car22是" + car22);
//                    }
//
//                    Car car3 = new Car();
//                    Car car32 = new Car();
//                    if (carList.size() >= 3) {
//                        car3 = carList.get(2);
//                        log.info("car3是" + car3);
//                    }
//                    if (carList2.size() >= 3) {
//                        car32 = carList2.get(2);
//                        log.info("car32是" + car32);
//                    }
//
//                    Car car4 = new Car();
//                    Car car42 = new Car();
//                    if (carList.size() >= 4) {
//                        car4 = carList.get(3);
//                        log.info("car3是" + car3);
//                    }
//                    if (carList2.size() >= 4) {
//                        car42 = carList2.get(3);
//                        log.info("car32是" + car32);
//                    }
//
//                    int car1RepeatNum = Optional.ofNullable(car1.getRepeatNum())
//                            .map(Integer::parseInt)
//                            .orElse(-1); // 提供默认值
//                    int car12RepeatNum = Optional.ofNullable(car12.getRepeatNum())
//                            .map(Integer::parseInt)
//                            .orElse(-1); // 提供默认值
//
//                    int car2RepeatNum = Optional.ofNullable(car2.getRepeatNum())
//                            .map(Integer::parseInt)
//                            .orElse(-1); // 提供默认值
//                    int car22RepeatNum = Optional.ofNullable(car22.getRepeatNum())
//                            .map(Integer::parseInt)
//                            .orElse(-1); // 提供默认值
//
//                    int car3RepeatNum = Optional.ofNullable(car3.getRepeatNum())
//                            .map(Integer::parseInt)
//                            .orElse(-1); // 提供默认值
//                    int car32RepeatNum = Optional.ofNullable(car32.getRepeatNum())
//                            .map(Integer::parseInt)
//                            .orElse(-1); // 提供默认值
//
//                    int car4RepeatNum = Optional.ofNullable(car4.getRepeatNum())
//                            .map(Integer::parseInt)
//                            .orElse(-1);
//                    int car42RepeatNum = Optional.ofNullable(car42.getRepeatNum())
//                            .map(Integer::parseInt)
//                            .orElse(-1);
//
//                    Object carNum1 = CacheUtil.getFromCache("carNum1");
//                    String carNum1String = carNum1 != null ? String.valueOf(carNum1) : "";
//                    log.info(carNum1 + "当前缓存carNum1是" + carNum1String);
//                    Object carNum2 = CacheUtil.getFromCache("carNum2");
//                    String carNum2String = carNum2 != null ? String.valueOf(carNum2) : "";
//                    log.info(carNum2 + "当前缓存carNum2是" + carNum2String);
//
//                    //防止循环时重复操作
////                    if (!carNum1String.contains(carNumPrefix0.getCarNum()) &&
////                            !carNum1String.contains(yymmdd0) &&
////                            !carNum1String.contains(carNumPrefix.getCarNum()) &&
////                            !carNum1String.contains(yymmdd) &&
////                            carNum1String.length() > carNumPrefix.getCarNum().length()) {
//
//                    Object repeat1cache = CacheUtil.getFromCache("repeat1");
//                    String repeat1String = repeat1cache != null ? String.valueOf(repeat1cache) : "";
//                    log.info("当前缓存repeat1String是" + repeat1String);
//                    Object repeat2cache = CacheUtil.getFromCache("repeat2");
//                    String repeat2String = repeat2cache != null ? String.valueOf(repeat2cache) : "";
//                    log.info("当前缓存repeat2String是" + repeat2String);
//                    //应该是连番有改变时才放行 &&
//                    //                            !repeat1.trim().isEmpty() && !repeat1String.isEmpty()
////-------------------------处理car1Num
//                    log.info("repeat1是"+repeat1);
//                    if (!repeat1.trim().equals(repeat1String) &&
//                            !repeat1.trim().isEmpty() ||
//                            repeat1String.trim().isEmpty()){
//                        log.info("当前1连番是："+repeat1.trim()+"上一个连番是："+repeat1String);
//
//                        Object allowPlus1 = CacheUtil.getFromCache("allowPlus1");
//                        int allowPlus1Int = 0;
//                        if (allowPlus1 != null) {
//                            log.info("allowPlus1现在是" + allowPlus1);
//                            //不能小于0
//                            allowPlus1Int = (Integer.parseInt(allowPlus1.toString()));
//                            if(allowPlus1Int > 0) {
//                                allowPlus1Int = (allowPlus1Int - 1);
//                                CacheUtil.putInCache("allowPlus1", allowPlus1Int);
//                            }
//                        }
//                        log.info(repeat1Int+"repeat1Int和allowPlus1Int是"+allowPlus1Int);
////                        log.info("car1RepeatNum是"+car1RepeatNum);
////                        log.info("car2RepeatNum是"+car2RepeatNum);
////                        log.info("car3RepeatNum是"+car3RepeatNum);
////                        log.info("repeat1String是"+repeat1String);
//                        if ((repeat1Int == 0 || repeat1Int == 1 || repeat1Int == 2
//                                || repeat1Int == 3 || repeat1Int == 4 || repeat1Int == 5)
//                                && !repeat1String.isEmpty()) {
//                            //连番经过了一个轮回，车身号前缀 + 1 然后拼接
//                            if (allowPlus1Int == 0 &&
//                                    ((car1RepeatNum == 99 || car1RepeatNum == 98 || car1RepeatNum == 97 || car1RepeatNum == 96)
//                                    || (car2RepeatNum == 99 || car2RepeatNum == 98 || car2RepeatNum == 97 || car2RepeatNum == 96)
//                                    || (car3RepeatNum == 99 || car3RepeatNum == 98 || car3RepeatNum == 97 || car3RepeatNum == 96)
//                                    || (car4RepeatNum == 99 || car4RepeatNum == 98 || car4RepeatNum == 97 || car4RepeatNum == 96)))
//                            {
//                                log.info("工位1连番经过了一个轮回，车身号 + 1");
//                                CacheUtil.putInCache("allowPlus1", 10);//清0时，才允许+1，这里重置为10
//                                if (carNumPrefix != null && carNumPrefix.getCarNum() != null) {
//                                    //1.旧方法
////                                    String carNumStr = carNumPrefix1.getCarNum();
////                                    if (carNumStr != null) {
////                                        car1Num = (Integer.parseInt(carNumStr) + 1) + repeat1.trim();
////                                    }
//                                    //2.新方法
//                                    int carNum = NumberUtils.toInt(carNumPrefix.getCarNum(), 0);
//                                    car1Num = (carNum + 1) + repeat1.trim();
////                                    car1Num = (Integer.parseInt(carNumPrefix.getCarNum()) + 1) + repeat1.trim();
//                                    //更新carNum1缓存
//                                    CacheUtil.putInCache("carNum1",car1Num.trim());
//                                }else {
//                                    Map map = new HashMap();
//                                    map.put("message",".车门铰链的车身号前缀未设置.");
//                                    String json = JSON.toJSONString(map);
//                                    webSocketServer.sendToAllClient(json);
//                                }
//
//                                //更新数据库
//                                if (carNumPrefix != null && carNumPrefix.getCarNum() != null) {
//                                    carNumPrefix.setCarNum(String.valueOf(Integer.parseInt(carNumPrefix.getCarNum()) + 1));
//                                    //XXXXX更新缓存(不用更新这个前缀的缓存，因为更新了数据库，上面在获取数据库数据的时候会一直更新这个前缀的缓存)
//                                    log.info("更新的carNumPrefix缓存是"+(Integer.parseInt(carNumPrefix.getCarNum()) + 1));
//                                    CacheUtil.putInCache("carNumPrefix",(Integer.parseInt(carNumPrefix.getCarNum())));
//                                }
//
//                                carNumPrefixMapper.updateById(carNumPrefix);
////                                log.info("car1Num是"+car1Num);
//                                //更新carNum1缓存
////                                CacheUtil.putInCache("carNum1",car1Num.trim());
//                            }else {//当前连番是012，但是前三个都不是99，98，97，不用 + 1，但是也需要拼接
//                                log.info("当前连番是012，连番正常拼接"+carNumPrefix);
//                                if (carNumPrefix != null) {
//                                    car1Num = carNumPrefix.getCarNum() + repeat1.trim();
//                                }else {
//                                    car1Num = "null" + repeat1.trim();
//                                    Map map = new HashMap();
//                                    map.put("message",".车门铰链的车身号前缀未设置.");
//                                    String json = JSON.toJSONString(map);
//                                    webSocketServer.sendToAllClient(json);
//                                }
////                                log.info("car1Num是" + car1Num);
//                                //更新carNum1缓存
//                                CacheUtil.putInCache("carNum1", car1Num.trim());
//                            }
//                        } else if (repeat1Int == -1) {//1.repeat1Int未获取到，2.初始??
//                            log.info("repeat1未获取到，不处理");
////                        car1Num = carNumPrefix.getCarNum() + repeat1Int + 1;
//                        } else {//连番 + 1 再拼接
//                            log.info("连番正常拼接"+carNumPrefix);
//                            if (carNumPrefix != null) {
//                                car1Num = carNumPrefix.getCarNum() + repeat1.trim();
//                            }else {
//                                car1Num = "null" + repeat1.trim();
//                                Map map = new HashMap();
//                                map.put("message",".车门铰链的车身号前缀未设置.");
//                                String json = JSON.toJSONString(map);
//                                webSocketServer.sendToAllClient(json);
//                            }
////                            log.info("car1Num是" + car1Num.trim());
//                            //更新carNum1缓存
//                            CacheUtil.putInCache("carNum1", car1Num.trim());
//                        }
//                    }else {
//                        car1Num = carNum1String.trim();
//                        CacheUtil.putInCache("carNum1",car1Num.trim());
//                        log.info("1连番拼接过了"+car1Num);
//                    }
////-------------------------处理car2Num
//                    if (!repeat2.trim().equals(repeat2String) &&
//                            !repeat2.trim().isEmpty() ||
//                            repeat2String.trim().isEmpty()){
//                        log.info("当前2连番是："+repeat2.trim()+"上一个连番是："+repeat2String);
//
//                        Object allowPlus2 = CacheUtil.getFromCache("allowPlus2");
//                        int allowPlus2Int = 0;
//                        if (allowPlus2 != null) {
//                            log.info("allowPlus2现在是" + allowPlus2);
//                            //不能小于0
//                            allowPlus2Int = (Integer.parseInt(allowPlus2.toString()));
//                            if(allowPlus2Int > 0) {
//                                allowPlus2Int = (allowPlus2Int - 1);
//                                CacheUtil.putInCache("allowPlus2", allowPlus2Int);
//                            }
//                        }
//
//                        if ((repeat2Int == 0 || repeat2Int == 1 || repeat2Int == 2
//                                || repeat2Int == 3 || repeat2Int == 4 || repeat2Int == 5)
//                                && !repeat2String.isEmpty()) {
//                            //连番经过了一个轮回，车身号前缀 + 1 然后拼接
//                            if (allowPlus2Int == 0 &&
//                                    ((car12RepeatNum == 99 || car12RepeatNum == 98 || car12RepeatNum == 97 || car12RepeatNum == 96)
//                                            || (car22RepeatNum == 99 || car22RepeatNum == 98 || car22RepeatNum == 97 || car22RepeatNum == 96)
//                                            || (car32RepeatNum == 99 || car32RepeatNum == 98 || car32RepeatNum == 97 || car32RepeatNum == 96)
//                                            || (car42RepeatNum == 99 || car42RepeatNum == 98 || car42RepeatNum == 97|| car42RepeatNum == 96)))
//                            {
//                                log.info("工位2连番经过了一个轮回，车身号 + 1");
//                                CacheUtil.putInCache("allowPlus2", 10);//清0时，才允许+1，这里重置为10
//                                if (carNumPrefix2 != null && carNumPrefix2.getCarNum() != null) {
//                                   //1.旧方法
////                                    String carNumStr = carNumPrefix2.getCarNum();
////                                    if (carNumStr != null) {
////                                        car2Num = (Integer.parseInt(carNumStr) + 1) + repeat2.trim();
////                                    }
//                                    //2.新方法//该方法在遇到null或者无法解析的字符串时，会返回默认值
//                                    int carNum = NumberUtils.toInt(carNumPrefix2.getCarNum(), 0);
//                                    car2Num = (carNum + 1) + repeat2.trim();
////                                       car2Num = (Integer.parseInt(carNumPrefix2.getCarNum()) + 1) + repeat2.trim();
//                                        //更新carNum2缓存
//                                        CacheUtil.putInCache("carNum2", car2Num.trim());
//                                }else {
//                                    Map map = new HashMap();
//                                    map.put("message",".发动机盖的车身号前缀未设置.");
//                                    String json = JSON.toJSONString(map);
//                                    webSocketServer.sendToAllClient(json);
//                                }
//
//                                //更新数据库
//                                if (carNumPrefix2 != null && carNumPrefix2.getCarNum() != null) {
//                                    carNumPrefix2.setCarNum(String.valueOf(Integer.parseInt(carNumPrefix2.getCarNum()) + 1));
//                                    //XXXXX更新缓存(不用更新这个前缀的缓存，因为更新了数据库，上面在获取数据库数据的时候会一直更新这个前缀的缓存)
//                                    log.info("更新的carNumPrefix2缓存是"+(Integer.parseInt(carNumPrefix2.getCarNum()) + 1));
//                                    CacheUtil.putInCache("carNumPrefix2",(Integer.parseInt(carNumPrefix2.getCarNum())));
//                                }
//
//                                carNumPrefixMapper.updateById(carNumPrefix2);
////                                log.info("car2Num是"+car2Num);
//                                //更新carNum1缓存
////                                CacheUtil.putInCache("carNum1",car1Num.trim());
//                            }else {//当前连番是012，但是前三个都不是99，98，97，不用 + 1，但是也需要拼接
//                                log.info("当前连番是012，连番正常拼接"+carNumPrefix2);
//                                if (carNumPrefix2 != null) {
//                                    car2Num = carNumPrefix2.getCarNum() + repeat2.trim();
//                                }else {
//                                    car2Num = "null" + repeat2.trim();
//                                    Map map = new HashMap();
//                                    map.put("message",".发动机盖的车身号前缀未设置.");
//                                    String json = JSON.toJSONString(map);
//                                    webSocketServer.sendToAllClient(json);
//                                }
////                                log.info("car2Num是" + car2Num.trim());
//                                //更新carNum2缓存
//                                CacheUtil.putInCache("carNum2", car2Num.trim());
//                            }
//                        } else if (repeat2Int == -1) {//1.repeat1Int未获取到，2.初始??
//                            log.info("repeat2未获取到，不处理");
////                        car1Num = carNumPrefix.getCarNum() + repeat1Int + 1;
//                        } else {//连番 + 1 再拼接
//                            log.info("连番正常拼接"+carNumPrefix2);
//                            if (carNumPrefix2 != null) {
//                                car2Num = carNumPrefix2.getCarNum() + repeat2.trim();
//                            }else {
//                                car2Num = "null" + repeat2.trim();
//                                Map map = new HashMap();
//                                map.put("message",".发动机盖的车身号前缀未设置.");
//                                String json = JSON.toJSONString(map);
//                                webSocketServer.sendToAllClient(json);
//                            }
////                            log.info("car2Num是" + car2Num.trim());
//                            //更新carNum1缓存
//                            CacheUtil.putInCache("carNum2", car2Num.trim());
//                        }
//                    }else {
//                        car2Num = carNum2String.trim();
//                        CacheUtil.putInCache("carNum2",car2Num.trim());
//                        log.info("2连番拼接过了"+car2Num);
//                    }
////                }catch(NumberFormatException e){
////                    log.info("车身号和连番号强转拼接数据转换异常");
////                    e.printStackTrace();
////                } catch(InterruptedException e){
////                    log.info("InterruptedException异常");
////                    e.printStackTrace();
//////                    throw new RuntimeException(e);
////                }
////                }
//
//            //TODO 复制一份过来
//
//
//        Map<String, String> map = new HashMap<>();
//        if(car1Num != null) {
//            map.put("car1Num", car1Num.trim());
//        }else {
//            map.put("car1Num", "null");
//        }
//        if(car1Type != null) {
//            map.put("car1Type", car1Type.trim());
//        }
//        map.put("repeat1", repeat1.trim());
//
//        LambdaQueryWrapper<TorqueStandards> torqueStandardsWrapper1 = new LambdaQueryWrapper<>();
//        if (car1Type != null) {
//            torqueStandardsWrapper1.eq(TorqueStandards::getCarType, car1Type.trim());
//        }
////        log.info("车型car1Type是"+car1Type);
//        torqueStandardsWrapper1.eq(TorqueStandards::getWorkingPositionId, MessageConstant.workingPosition1);
//        int count1 = torqueStandardsMapper.selectCount(torqueStandardsWrapper1);
////        log.info("count1是"+count1);
//        if(count1 == 0){
//            map.put("standard1min", "");
//            map.put("standard1max", "");
//            CacheUtil.removeFromCache("standard1");
//            //CacheUtil.removeFromCache("standard1max");
//        } else if(count1 == 1) {
//            TorqueStandards torqueStandards = torqueStandardsMapper.selectOne(torqueStandardsWrapper1);
////            log.info("能拿到torqueStandards吗"+torqueStandards);
////            Map<String, Object> standard1 = new HashMap();
////            standard1.put("minimumTorque", torqueStandards.getMinimumTorque());
////            standard1.put("maximumTorque", torqueStandards.getMaximumTorque());
////            standard1.put("unit", torqueStandards.getUnit());
//
//            CacheUtil.putInCache("standard1",torqueStandards);
//            //CacheUtil.putInCache("standard1max",torqueStandards.getMaximumTorque());
////            String json = JSON.toJSONString(torqueStandards);//standard1
//            map.put("standard1min", String.valueOf(torqueStandards.getMinimumTorque()));
//            map.put("standard1max", String.valueOf(torqueStandards.getMaximumTorque()));
////            map.put("standard1", String.valueOf(torqueStandards));
////            log.info("standard1村井去了吗"+map.get("standard1"));
//        }else {
//            log.info("数据异常-----");
//            map.put("standard1min", "数据异常");
//            map.put("standard1max", "数据异常");
//            CacheUtil.removeFromCache("standard1");
////            //CacheUtil.removeFromCache("standard1max");
//        }
//
//        if(car2Num != null) {
//            map.put("car2Num", car2Num.trim());
//        }else {
//            map.put("car2Num", "null");
//        }
//        if(car2Type != null) {
//            map.put("car2Type", car2Type.trim());
//        }
//        map.put("repeat2", repeat2.trim());
//
//        LambdaQueryWrapper<TorqueStandards> torqueStandardsWrapper2 = new LambdaQueryWrapper<>();
//        if (car2Type != null) {
//            torqueStandardsWrapper2.eq(TorqueStandards::getCarType, car2Type.trim());
//        }
//        torqueStandardsWrapper2.eq(TorqueStandards::getWorkingPositionId, MessageConstant.workingPosition2);
//        int count2 = torqueStandardsMapper.selectCount(torqueStandardsWrapper2);
//        if(count2 == 0){
//            map.put("standard2min", "");
//            map.put("standard2max", "");
//            CacheUtil.removeFromCache("standard2");
//            //CacheUtil.removeFromCache("standard2max");
//        } else if(count2 == 1) {
//            TorqueStandards torqueStandards = torqueStandardsMapper.selectOne(torqueStandardsWrapper2);
//            CacheUtil.putInCache("standard2",torqueStandards);
//            //CacheUtil.putInCache("standard2max",torqueStandards.getMaximumTorque());
//            map.put("standard2min", torqueStandards.getMinimumTorque().toString());
//            map.put("standard2max", torqueStandards.getMaximumTorque().toString());
////            String json = JSON.toJSONString(torqueStandards);
////            map.put("standard2", json);
//        }else {
//            log.info("数据异常-----");
//            map.put("standard2min", "数据异常");
//            map.put("standard2max", "数据异常");
//            CacheUtil.removeFromCache("standard2");
//            //CacheUtil.removeFromCache("standard2max");
//        }
//        //把map转为json
//        String json = JSON.toJSONString(map);
////        log.info("车的json是"+json);
//        webSocketServer.sendToAllClient(json);//推消息
////        if(car1Num.trim().isEmpty() && car1Type.trim().isEmpty()
////        && repeat1.trim().isEmpty() &&
////                car2Num.trim().isEmpty() && car2Type.trim().isEmpty()
////                && repeat2.trim().isEmpty()){
////            return null;
////        }
//        return map;
//    }
//
//    //--------------------------------------------
//
//    //优化前
////    private Map<String, String> process(List<String> nodeList) {
////        log.info("nodeList是" + nodeList);
////
////        Map<String, String> resultMap = new HashMap<>();
////        Pattern pattern = Pattern.compile("=([^}]+)$");
////
////        String nodeListString = nodeList.toString();
////        if((nodeListString.contains(carNodeProperties.getCarTypeSuffix1()) &&
////                nodeListString.contains(carNodeProperties.getCarTypeSuffix2()))
////                ||
////                (nodeListString.contains(carNodeProperties.getRepeatSuffix1()) &&
////                        nodeListString.contains(carNodeProperties.getRepeatSuffix2()))){
////        for (String node : nodeList) {
//////            log.info("node是"+node);
//////                log.info("node是"+node);
////                Matcher matcher = pattern.matcher(node);
//////                log.info("matcher是"+matcher);
////                if (matcher.find()) {
////                    String value = matcher.group(1).trim();
//////                    log.info("value是"+value);
////                    if(node.contains(carNodeProperties.getRepeatSuffix1())) {
////                        //转16进制
//////                        int hex = Integer.parseInt(value, 16);
////                        String hex = Integer.toHexString(Integer.parseInt(value)); // 将十进制整数转换为十六进制字符串
//////                        log.info("转16进制后" + hex);
////                        resultMap.put("asciiBuilder1", hex);
////                    }else if(node.contains(carNodeProperties.getRepeatSuffix2())){
////                        //转16进制
//////                        int hex = Integer.parseInt(value, 16);
////                        String hex = Integer.toHexString(Integer.parseInt(value)); // 将十进制整数转换为十六进制字符串
////                        log.info("转16进制后" + hex);
////                        resultMap.put("asciiBuilder2", hex);
////                    } else if(node.contains(carNodeProperties.getCarTypeSuffix1())){
////                        resultMap.put("asciiBuilder1", value);
////                    } else if(node.contains(carNodeProperties.getCarTypeSuffix2())) {
////                        resultMap.put("asciiBuilder2", value);
////                    }
////                }
////        }
////         }
////        log.info("resultMap---------"+resultMap);
////        return resultMap;
////    }
//
//    //优化后
//    private Map<String, String> process(List<String> nodeList) {
////        log.info("开始处理节点列表，节点数量: {}", nodeList.size());
//
//        Map<String, String> resultMap = new HashMap<>();
//        if (CollectionUtils.isEmpty(nodeList)) {
//            log.warn("节点列表为空，直接返回空结果");
//            return resultMap;
//        }
//
//        Pattern valuePattern = Pattern.compile("=([^}]+)$");
//        String nodeListStr = String.join("", nodeList);
//
//        boolean containsCarTypeSuffixes =
//                nodeListStr.contains(carNodeProperties.getCarTypeSuffix1()) &&
//                        nodeListStr.contains(carNodeProperties.getCarTypeSuffix2());
//
//        boolean containsRepeatSuffixes =
//                nodeListStr.contains(carNodeProperties.getRepeatSuffix1()) &&
//                        nodeListStr.contains(carNodeProperties.getRepeatSuffix2());
//
//        if (containsCarTypeSuffixes || containsRepeatSuffixes) {
//            for (String node : nodeList) {
//                processNode(node, valuePattern, resultMap);
//            }
//        }
//
//        log.info("process处理完成，结果: {}", resultMap);
//        return resultMap;
//    }
//
//    private void processNode(String node, Pattern valuePattern, Map<String, String> resultMap) {
//        Matcher matcher = valuePattern.matcher(node);
//        if (!matcher.find()) {
//            return;
//        }
//
//        String value = matcher.group(1).trim();
//        if (StringUtils.isEmpty(value)) {
//            log.debug("匹配到的value为空，跳过处理: {}", node);
//            return;
//        }
//
//        try {
//            if (node.contains(carNodeProperties.getRepeatSuffix1())) {
//                resultMap.put("asciiBuilder1", convertToHex(value));
//            } else if (node.contains(carNodeProperties.getRepeatSuffix2())) {
//                resultMap.put("asciiBuilder2", convertToHex(value));
//            } else if (node.contains(carNodeProperties.getCarTypeSuffix1())) {
//                resultMap.put("asciiBuilder1", value);
//            } else if (node.contains(carNodeProperties.getCarTypeSuffix2())) {
//                resultMap.put("asciiBuilder2", value);
//            }
//        } catch (NumberFormatException e) {
//            log.error("数值转换失败，节点: {}, 值: {}", node, value, e);
//        }
//    }
//
//    private String convertToHex(String value) {
//        return Integer.toHexString(Integer.parseInt(value));
//    }
//
//}